+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.as.specific.extended.community.AsSpecificExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.as.specific.extended.community.AsSpecificExtendedCommunityBuilder;
-
-public class ASSpecificExtendedCommunityTest {
-
- private final boolean transitive = true;
- private final AsNumber globalAdmin = new AsNumber(429496729800L);
-
- @Test
- @Ignore
- // FIXME: length is not implemented
- public void testOverflows() {
- try {
- new AsSpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
- new byte[] {}).build();
- fail("Local Administrator has illegal length!");
- } catch (final IllegalArgumentException e) {
- assertEquals("Invalid Local Administrator", e.getMessage());
- }
- }
-
- @Test
- public void testGetters() {
- final AsSpecificExtendedCommunity asSpecExCom = new AsSpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(
- this.globalAdmin).setLocalAdministrator(new byte[] { 10, 0, 0, 1 }).build();
- assertEquals(new AsNumber(429496729800L), asSpecExCom.getGlobalAdministrator());
- assertArrayEquals(new byte[] { 10, 0, 0, 1 }, asSpecExCom.getLocalAdministrator());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
-
-public class ClusterIdentifierTest {
-
- @Test
- public void testClusterIdentifier() {
- final ClusterIdentifier id = new ClusterIdentifier(new byte[] { 13, 14, 15, 16 });
- // FIXME: uncomment, once the generated code has length precondition
- // try {
- // new ClusterIdentifier(new byte[] { 5, 6 });
- // fail("Cluster ID is invalid!");
- // } catch (final IllegalArgumentException e) {
- // assertEquals("Invalid Cluster ID", e.getMessage());
- // }
-
- final ClusterIdentifier id1 = new ClusterIdentifier(new byte[] { 13, 14, 15, 16 });
-
- assertEquals(id1.toString(), id.toString());
-
- assertArrayEquals(id1.getValue(), new byte[] { 13, 14, 15, 16 });
- }
-
- @Test
- public void testOrigin() {
- final BgpOrigin or = BgpOrigin.Egp;
- assertEquals(or.name(), "Egp");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
-
-public class Inet4SpecificExtendedCommunityTest {
-
- private boolean transitive;
- private Ipv4Address globalAdmin;
- private byte[] localAdmin;
-
- private Inet4SpecificExtendedCommunity community;
-
- @Before
- public void init() {
- this.transitive = true;
- this.globalAdmin = new Ipv4Address("10.0.0.1");
- this.localAdmin = new byte[] { 10, 1 };
- this.community = new Inet4SpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
- this.localAdmin).build();
- }
-
- @Test
- @Ignore
- // FIXME: length is not implemented
- public void testOverflows() {
- try {
- new Inet4SpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
- new byte[] { 10, 0, 1 }).build();
- fail("Invalid length of local administrator!");
- } catch (final IllegalArgumentException e) {
- assertEquals("Invalid Local Administrator", e.getMessage());
- }
- }
-
- @Test
- public void testGetGlobalAdmin() {
- final Ipv4Address globalAdmin = new Ipv4Address("10.0.0.1");
- assertEquals(globalAdmin, this.community.getGlobalAdministrator());
- }
-
- @Test
- public void testGetLocalAdmin() {
- final byte[] localAdmin = new byte[] { 10, 1 };
- assertArrayEquals(localAdmin, this.community.getLocalAdministrator());
- }
-
- @Test
- public void testIsTransitive() {
- assertTrue(this.community.isTransitive());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.opaque.extended.community.OpaqueExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.opaque.extended.community.OpaqueExtendedCommunityBuilder;
-
-public class OpaqueExtendedCommunityTest {
-
- private boolean transitive;
- private byte[] value;
-
- private OpaqueExtendedCommunity community;
-
- @Before
- public void init() {
- this.transitive = true;
- this.value = new byte[] { 1, 5, 9, 3, 5, 7 };
- this.community = new OpaqueExtendedCommunityBuilder().setTransitive(this.transitive).setValue(this.value).build();
- }
-
- @Test
- @Ignore
- // FIXME: when length is implemented
- public void testOverflows() {
- try {
- new OpaqueExtendedCommunityBuilder().setTransitive(this.transitive).setValue(new byte[] { 0, 1, 2, 3, 4, 5, 6, }).build();
- fail("Constructor successful unexpectedly");
- } catch (final IllegalArgumentException e) {
- assertEquals("Invalid value", e.getMessage());
- }
- }
-
- @Test
- public void testGetValue() {
- assertArrayEquals(new byte[] { 1, 5, 9, 3, 5, 7 }, this.community.getValue());
- }
-
- @Test
- public void testIsTransitive() {
- assertTrue(this.community.isTransitive());
- }
-
- @Test
- public void testToString() {
- final OpaqueExtendedCommunity c = new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(this.value).build();
- assertNotSame(c.toString(), this.community.toString());
- }
-}
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bgp-parser-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>bgp-rib-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
-/**
- *
- */
public final class Activator implements BGPExtensionProviderActivator {
@Override
public void start(final BGPExtensionProviderContext context) throws Exception {
context.registerAddressFamily(LinkstateAddressFamily.class, 16388);
context.registerSubsequentAddressFamily(LinkstateSubsequentAddressFamily.class, 71);
- context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
- new LinkstateNlriParser(false));
- context.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class,
- new LinkstateNlriParser(true));
+ context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateNlriParser(false));
+ context.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class, new LinkstateNlriParser(true));
context.registerAttributeParser(LinkstateAttributeParser.TYPE, new LinkstateAttributeParser());
}
/**
* Parser for Link State information.
*
- * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-01">BGP-LS draft</a>
+ * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-03">BGP-LS draft</a>
*/
public class LinkstateAttributeParser implements AttributeParser {
// FIXME: update to IANA number once it is known
private static final int LENGTH_SIZE = 2;
- private static final Set<Integer> nodeTlvs = Sets.newHashSet(263, 1024, 1025, 1026, 1027, 1028, 1029);
+ private static final Set<Integer> NODE_TLVS = Sets.newHashSet(263, 1024, 1025, 1026, 1027, 1028, 1029);
- private static final Set<Integer> linkTlvs = Sets.newHashSet(1028, 1029, 1030, 1031, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095,
+ private static final Set<Integer> LINK_TLVS = Sets.newHashSet(1028, 1029, 1030, 1031, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095,
1096, 1097, 1098);
- private static final Set<Integer> prefixTlvs = Sets.newHashSet(1152, 1153, 1154, 1155, 1156, 1157);
+ private static final Set<Integer> PREFIX_TLVS = Sets.newHashSet(1152, 1153, 1154, 1155, 1156, 1157);
@Override
public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPParsingException {
builder.addAugmentation(PathAttributes1.class, a);
}
-
- public static boolean verifyLink(final Set<Integer> keys) {
+ private static boolean verifyLink(final Set<Integer> keys) {
for (final Integer i : keys) {
- if (!linkTlvs.contains(i)) {
+ if (!LINK_TLVS.contains(i)) {
logger.warn("Invalid link attribute {}", i);
return false;
}
return true;
}
- public static boolean verifyNode(final Set<Integer> keys) {
+ private static boolean verifyNode(final Set<Integer> keys) {
for (final Integer i : keys) {
- if (!nodeTlvs.contains(i)) {
+ if (!NODE_TLVS.contains(i)) {
logger.warn("Invalid node attribute {}", i);
return false;
}
return true;
}
- public static boolean verifyPrefix(final Set<Integer> keys) {
+ private static boolean verifyPrefix(final Set<Integer> keys) {
for (final Integer i : keys) {
- if (!prefixTlvs.contains(i)) {
+ if (!PREFIX_TLVS.contains(i)) {
logger.warn("Invalid prefix attribute {}", i);
return false;
}
return true;
}
- protected static LinkstatePathAttribute parseLinkState(final byte[] bytes) throws BGPParsingException {
+ private static LinkstatePathAttribute parseLinkState(final byte[] bytes) throws BGPParsingException {
final Map<Integer, ByteList> map = new HashMap<Integer, ByteList>();
int byteOffset = 0;
while (byteOffset != bytes.length) {
final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- ByteList values = map.containsKey(type) ? values = map.get(type) : new ByteList();
+ final ByteList values = map.containsKey(type) ? map.get(type) : new ByteList();
values.add(value);
map.put(type, values);
byteOffset += length;
* @return {@link LinkAttributes}
* @throws BGPParsingException if a link attribute is not recognized
*/
- public static LinkAttributes parseLinkAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+ private static LinkAttributes parseLinkAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
final LinkAttributesBuilder builder = new LinkAttributesBuilder();
for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
- logger.debug("Link attribute TLV {}", entry.getKey());
+ logger.trace("Link attribute TLV {}", entry.getKey());
for (final byte[] value : entry.getValue().getBytes()) {
case 1028:
final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setLocalIpv4RouterId(lipv4);
- logger.trace("Parsed IPv4 Router-ID of local node: {}", lipv4);
+ logger.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
break;
case 1029:
final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setLocalIpv6RouterId(lipv6);
- logger.trace("Parsed IPv6 Router-ID of local node: {}", lipv6);
+ logger.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
break;
case 1030:
final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setRemoteIpv4RouterId(ripv4);
- logger.trace("Parsed IPv4 Router-ID of remote node: {}", ripv4);
+ logger.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
break;
case 1031:
final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setRemoteIpv6RouterId(ripv6);
- logger.trace("Parsed IPv6 Router-ID of remote node: {}", ripv6);
+ logger.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
break;
case 1088:
builder.setAdminGroup(new AdministrativeGroup(ByteArray.bytesToLong(value)));
- logger.trace("Parsed Administrative Group {}", builder.getAdminGroup());
+ logger.debug("Parsed Administrative Group {}", builder.getAdminGroup());
break;
case 1089:
builder.setMaxLinkBandwidth(new Bandwidth(value));
- logger.trace("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
+ logger.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
break;
case 1090:
builder.setMaxReservableBandwidth(new Bandwidth(value));
- logger.trace("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
+ logger.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
break;
case 1091:
int index = 0;
index += 4;
}
builder.setUnreservedBandwidth(unreservedBandwidth);
- logger.trace("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
+ logger.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
break;
case 1092:
builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(value)));
- logger.trace("Parsed Metric {}", builder.getTeMetric());
+ logger.debug("Parsed Metric {}", builder.getTeMetric());
break;
case 1093:
final LinkProtectionType lpt = LinkProtectionType.forValue(UnsignedBytes.toInt(value[0]));
throw new BGPParsingException("Link Protection Type not recognized: " + UnsignedBytes.toInt(value[0]));
}
builder.setLinkProtection(lpt);
- logger.trace("Parsed Link Protection Type {}", lpt);
+ logger.debug("Parsed Link Protection Type {}", lpt);
break;
case 1094:
final boolean[] bits = ByteArray.parseBits(value[0]);
builder.setMplsProtocol(new MplsProtocolMask(bits[0], bits[1]));
- logger.trace("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
+ logger.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
break;
case 1095:
builder.setMetric(new Metric(ByteArray.bytesToLong(value)));
- logger.trace("Parsed Metric {}", builder.getMetric());
+ logger.debug("Parsed Metric {}", builder.getMetric());
break;
case 1096:
int i = 0;
i += 4;
}
builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
- logger.trace("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
+ logger.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
break;
case 1097:
final byte[] opaque = value;
- logger.trace("Parsed Opaque value : {}", Arrays.toString(opaque));
+ logger.debug("Parsed Opaque value : {}", Arrays.toString(opaque));
break;
case 1098:
final String name = new String(value, Charsets.US_ASCII);
builder.setLinkName(name);
- logger.trace("Parsed Link Name : ", name);
+ logger.debug("Parsed Link Name : {}", name);
break;
default:
throw new BGPParsingException("Link Attribute not recognized, type: " + entry.getKey());
}
}
}
- logger.debug("Finished parsing Link Attributes.");
+ logger.trace("Finished parsing Link Attributes.");
return builder.build();
}
* @return {@link NodeAttributes}
* @throws BGPParsingException if a node attribute is not recognized
*/
- public static NodeAttributes parseNodeAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+ private static NodeAttributes parseNodeAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
final List<TopologyIdentifier> topologyMembership = Lists.newArrayList();
final List<IsisAreaIdentifier> areaMembership = Lists.newArrayList();
final NodeAttributesBuilder builder = new NodeAttributesBuilder();
for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
- logger.debug("Node attribute TLV {}", entry.getKey());
+ logger.trace("Node attribute TLV {}", entry.getKey());
for (final byte[] value : entry.getValue().getBytes()) {
switch (entry.getKey()) {
case 263:
while (i != value.length) {
final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(ByteArray.subByte(value, i, 2)) & 0x3fff);
topologyMembership.add(topId);
- logger.trace("Parsed Topology Identifier: {}", topId);
+ logger.debug("Parsed Topology Identifier: {}", topId);
i += 2;
}
break;
case 1024:
final boolean[] flags = ByteArray.parseBits(value[0]);
builder.setNodeFlags(new NodeFlagBits(flags[0], flags[1], flags[2], flags[3]));
- logger.trace("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
+ logger.debug("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
break;
case 1025:
logger.debug("Ignoring opaque value: {}.", Arrays.toString(value));
break;
case 1026:
builder.setDynamicHostname(new String(value, Charsets.US_ASCII));
- logger.trace("Parsed Node Name {}", builder.getDynamicHostname());
+ logger.debug("Parsed Node Name {}", builder.getDynamicHostname());
break;
case 1027:
final IsisAreaIdentifier ai = new IsisAreaIdentifier(value);
areaMembership.add(ai);
- logger.trace("Parsed AreaIdentifier {}", ai);
+ logger.debug("Parsed AreaIdentifier {}", ai);
break;
case 1028:
final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setIpv4RouterId(ip4);
- logger.trace("Parsed IPv4 Router Identifier {}", ip4);
+ logger.debug("Parsed IPv4 Router Identifier {}", ip4);
break;
case 1029:
final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setIpv6RouterId(ip6);
- logger.trace("Parsed IPv6 Router Identifier {}", ip6);
+ logger.debug("Parsed IPv6 Router Identifier {}", ip6);
break;
default:
throw new BGPParsingException("Node Attribute not recognized, type: " + entry.getKey());
}
builder.setTopologyIdentifier(topologyMembership);
builder.setIsisAreaId(areaMembership);
- logger.debug("Finished parsing Node Attributes.");
+ logger.trace("Finished parsing Node Attributes.");
return builder.build();
}
* @return {@link PrefixAttributes}
* @throws BGPParsingException if some prefix attributes is not recognized
*/
- public static PrefixAttributes parsePrefixAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+ private static PrefixAttributes parsePrefixAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
final List<RouteTag> routeTags = Lists.newArrayList();
final List<ExtendedRouteTag> exRouteTags = Lists.newArrayList();
import java.math.BigInteger;
import java.util.Arrays;
+import java.util.List;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.CRouterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisPseudonodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.DestinationType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
public final class LinkstateNlriParser implements NlriParser {
byteOffset += LENGTH_SIZE;
final NodeIdentifier remote = null;
if (type == 257) {
- builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length)));
+ builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length),
+ false));
byteOffset += length;
}
builder.setLinkDescriptors(parseLinkDescriptors(ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset)));
final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- logger.debug("Parsing Link Descriptor: {}", Arrays.toString(value));
+ logger.trace("Parsing Link Descriptor: {}", Arrays.toString(value));
switch (type) {
case 258:
builder.setLinkLocalIdentifier(ByteArray.subByte(value, 0, 4));
builder.setLinkRemoteIdentifier(ByteArray.subByte(value, 4, 4));
- logger.trace("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
+ logger.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
builder.getLinkRemoteIdentifier());
break;
case 259:
final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
builder.setIpv4InterfaceAddress(lipv4);
- logger.trace("Parsed IPv4 interface address {}.", lipv4);
+ logger.debug("Parsed IPv4 interface address {}.", lipv4);
break;
case 260:
final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
builder.setIpv4NeighborAddress(ripv4);
- logger.trace("Parsed IPv4 neighbor address {}.", ripv4);
+ logger.debug("Parsed IPv4 neighbor address {}.", ripv4);
break;
case 261:
final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
builder.setIpv6InterfaceAddress(lipv6);
- logger.trace("Parsed IPv6 interface address {}.", lipv6);
+ logger.debug("Parsed IPv6 interface address {}.", lipv6);
break;
case 262:
final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
builder.setIpv6NeighborAddress(ripv6);
- logger.trace("Parsed IPv6 neighbor address {}.", ripv6);
+ logger.debug("Parsed IPv6 neighbor address {}.", ripv6);
break;
case 263:
final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
builder.setMultiTopologyId(topId);
- logger.trace("Parsed topology identifier {}.", topId);
+ logger.debug("Parsed topology identifier {}.", topId);
break;
default:
throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
}
byteOffset += length;
}
- logger.debug("Finished parsing Link descriptors.");
+ logger.trace("Finished parsing Link descriptors.");
return builder.build();
}
- private static NodeIdentifier parseNodeDescriptors(final byte[] bytes) throws BGPParsingException {
+ private static NodeIdentifier parseNodeDescriptors(final byte[] bytes, final boolean local) throws BGPParsingException {
int byteOffset = 0;
AsNumber asnumber = null;
DomainIdentifier bgpId = null;
final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- logger.debug("Parsing Node Descriptor: {}", Arrays.toString(value));
+ logger.trace("Parsing Node Descriptor: {}", Arrays.toString(value));
switch (type) {
case 512:
asnumber = new AsNumber(ByteArray.bytesToLong(value));
- logger.trace("Parsed AS number {}", asnumber);
+ logger.debug("Parsed {}", asnumber);
break;
case 513:
bgpId = new DomainIdentifier(value);
- logger.trace("Parsed bgpId {}", bgpId);
+ logger.debug("Parsed {}", bgpId);
break;
case 514:
ai = new AreaIdentifier(value);
- logger.trace("Parsed area identifier {}", ai);
+ logger.debug("Parsed area identifier {}", ai);
break;
case 515:
- if (value.length == 6) {
- routerId = new CIsisNodeBuilder().setIsisNode(
- new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
- } else if (value.length == 7) {
- if (value[6] == 0) {
- logger.warn("PSN octet is 0. Ignoring System ID.");
- routerId = new CIsisNodeBuilder().setIsisNode(
- new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
- break;
- } else {
- final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
- new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
- routerId = new CIsisPseudonodeBuilder().setIsisPseudonode(
- new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
- }
- } else if (value.length == 4) {
- routerId = new COspfNodeBuilder().setOspfNode(
- new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
- } else if (value.length == 8) {
- final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
- final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
- routerId = new COspfPseudonodeBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
- }
- logger.trace("Parsed Router Identifier {}", routerId);
+ routerId = parseRouterId(value);
+ logger.debug("Parsed Router Identifier {}", routerId);
break;
default:
throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
}
byteOffset += length;
}
- logger.debug("Finished parsing Node descriptors.");
- return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+ logger.trace("Finished parsing Node descriptors.");
+ return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
+ routerId).build()
+ : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+ }
+
+ private static CRouterIdentifier parseRouterId(final byte[] value) throws BGPParsingException {
+ if (value.length == 6) {
+ return new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+ }
+ if (value.length == 7) {
+ if (value[6] == 0) {
+ logger.warn("PSN octet is 0. Ignoring System ID.");
+ return new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+ } else {
+ final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
+ return new CIsisPseudonodeBuilder().setIsisPseudonode(
+ new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
+ }
+ }
+ if (value.length == 4) {
+ return new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
+ }
+ if (value.length == 8) {
+ final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
+ final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
+ return new COspfPseudonodeBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
+ }
+ throw new BGPParsingException("Router Id of invalid length " + value.length);
}
- private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes) throws BGPParsingException {
+ private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes)
+ throws BGPParsingException {
int byteOffset = 0;
final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
while (byteOffset != bytes.length) {
* @return BGPLinkMP or BGPNodeMP
* @throws BGPParsingException
*/
- private final CLinkstateDestination parseNlri(final byte[] nlri) throws BGPParsingException {
+ private List<CLinkstateDestination> parseNlri(final byte[] nlri) throws BGPParsingException {
if (nlri.length == 0) {
return null;
}
int byteOffset = 0;
- final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
+ final List<CLinkstateDestination> dests = Lists.newArrayList();
+
+ CLinkstateDestinationBuilder builder = null;
while (byteOffset != nlri.length) {
+ builder = new CLinkstateDestinationBuilder();
final NlriType type = NlriType.forValue(ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, TYPE_LENGTH)));
builder.setNlriType(type);
final int length = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
RouteDistinguisher distinguisher = null;
- if (isVpn) {
+ if (this.isVpn) {
// this parses route distinguisher
distinguisher = new RouteDistinguisher(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(nlri, byteOffset,
ROUTE_DISTINGUISHER_LENGTH))));
locallength = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
if (localtype == 256) {
- localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength));
+ localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength), true);
}
byteOffset += locallength;
builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
- final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0)
- - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength;
- logger.debug("Restlength {}", restLength);
+ final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+ - TYPE_LENGTH - LENGTH_SIZE - locallength;
+ logger.trace("Restlength {}", restLength);
switch (type) {
case Link:
parseLink(builder, ByteArray.subByte(nlri, byteOffset, restLength));
break;
}
byteOffset += restLength;
+ dests.add(builder.build());
}
- return builder.build();
+ return dests;
}
@Override
public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
- final CLinkstateDestination dst = parseNlri(nlri);
-
- // FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
- final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+ if (nlri.length == 0) {
+ return;
+ }
+ final List<CLinkstateDestination> dst = parseNlri(nlri);
- builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(s).build());
+ builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+ new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
}
@Override
- public final void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
- final CLinkstateDestination dst = parseNlri(nlri);
-
- // FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
- final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+ public void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
+ final List<CLinkstateDestination> dst = parseNlri(nlri);
- builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(s).build());
+ builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
NlriUtil.parseNextHop(nextHop, builder);
}
-}
\ No newline at end of file
+}
prefix inet;
revision-date 2010-09-24;
}
- import bgp-message { prefix bgp-msg;}
- import bgp-multiprotocol { prefix bgp-mp;}
- import bgp-types { prefix bgp-t;}
+ import bgp-message { prefix bgp-msg; }
+ import bgp-multiprotocol { prefix bgp-mp; }
+ import bgp-rib { prefix bgp-rib; }
+ import bgp-types { prefix bgp-t; }
import nps-concepts { prefix nps-c;}
import rsvp { prefix rsvp; revision-date 2013-08-20; }
}
grouping linkstate-destination {
- container c-linkstate-destination {
+ list c-linkstate-destination {
leaf nlri-type {
type nlri-type;
}
}
}
}
+
+ augment "/bgp-rib:loc-rib/bgp-rib:tables/bgp-rib:routes" {
+ case linkstate-routes {
+ container linkstate-routes {
+ leaf distinguisher {
+ type bgp-ls:route-distinguisher;
+ }
+ leaf protocol-id {
+ type bgp-ls:protocol-id;
+ }
+ leaf identifier {
+ type bgp-ls:identifier;
+ }
+
+ choice object-type {
+ case node {
+ container node-descriptors {
+ uses bgp-ls:node-identifier;
+ }
+ }
+ case link {
+ container local-node-descriptors {
+ uses bgp-ls:node-identifier;
+ }
+ container remote-node-descriptors {
+ uses bgp-ls:node-identifier;
+ }
+ container link-descriptors {
+ uses bgp-ls:link-identifiers;
+ leaf ipv4-interface-address {
+ type bgp-ls:ipv4-interface-identifier;
+ }
+ leaf ipv6-interface-address {
+ type bgp-ls:ipv6-interface-identifier;
+ }
+ leaf ipv4-neighbor-address {
+ type bgp-ls:ipv4-interface-identifier;
+ }
+ leaf ipv6-neighbor-address {
+ type bgp-ls:ipv6-interface-identifier;
+ }
+ leaf multi-topology-id {
+ type bgp-ls:topology-identifier;
+ }
+ }
+ }
+ case prefix {
+ leaf multi-topology-id {
+ type bgp-ls:topology-identifier;
+ }
+ leaf ospf-route-type {
+ when "../../protocol-id = 'ospf'";
+ type bgp-ls:ospf-route-type;
+ }
+ leaf ip-reachability-information {
+ type inet:ip-prefix;
+ }
+ }
+ }
+
+ uses bgp-rib:route;
+ }
+ }
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.linkstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.After;
+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.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+
+public class ActivatorTest {
+
+ private final Activator act = new Activator();
+
+ @Test
+ public void testActivator() throws Exception {
+ final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
+
+ assertNull(context.getAddressFamilyRegistry().classForFamily(16388));
+ assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(71));
+
+ this.act.start(context);
+
+ assertEquals(LinkstateAddressFamily.class, context.getAddressFamilyRegistry().classForFamily(16388));
+ assertEquals(LinkstateSubsequentAddressFamily.class, context.getSubsequentAddressFamilyRegistry().classForFamily(71));
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ this.act.stop();
+ } catch (final Exception e) {
+ fail("This exception should not occurr.");
+ }
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.linkstate;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
-
-public class AreaIdentifierTest {
-
- private AreaIdentifier identifier;
-
- @Before
- public void init() {
- final byte[] id = new byte[] {10,0,0,1};
- this.identifier = new AreaIdentifier(id);
- }
-
- @Test
- public void testGetBytes() {
- final byte[] id = new byte[] {10,0,0,1};
- assertArrayEquals(id, this.identifier.getValue());
- }
-
- @Test
- public void testToString(){
- final byte[] id1 = new byte[] {10,0,0,1};
- final AreaIdentifier l1 = new AreaIdentifier(id1);
- final String s1 = "AreaIdentifier [_value=[10, 0, 0, 1]]";
- assertEquals(s1, l1.toString());
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.linkstate;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
+
+public class LinkstateAttributeParserTest {
+
+ private static final byte[] LINK_ATTR = new byte[] { (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2a, (byte) 0x2a,
+ (byte) 0x2a, (byte) 0x2a, (byte) 0x04, (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0x2b, (byte) 0x2b, (byte) 0x2b,
+ (byte) 0x2b, (byte) 0x04, (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x04, (byte) 0x41, (byte) 0x00, (byte) 0x04, (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, (byte) 0x04,
+ (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x04, (byte) 0x43,
+ (byte) 0x00, (byte) 0x20, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x46, (byte) 0x43, (byte) 0x50,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x44,
+ (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03,
+ (byte) 0x00, (byte) 0x00, (byte) 0x0a };
+
+ private static final byte[] NODE_ATTR = new byte[] { (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x05, (byte) 0x31, (byte) 0x32,
+ (byte) 0x4b, (byte) 0x2d, (byte) 0x32, (byte) 0x04, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x72, (byte) 0x04,
+ (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x29 };
+
+ private final LinkstateAttributeParser parser = new LinkstateAttributeParser();
+
+ @Test
+ public void testPositiveLinks() {
+ final PathAttributesBuilder builder = new PathAttributesBuilder();
+ try {
+ this.parser.parseAttribute(LINK_ATTR, builder);
+ } catch (final BGPParsingException e) {
+ fail("No exception should occur.");
+ }
+ final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
+ final LinkAttributes ls = (LinkAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
+ assertNotNull(ls);
+
+ assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
+ assertEquals(new Long(10), ls.getMetric().getValue());
+ assertEquals(new Long(0), ls.getAdminGroup().getValue());
+ assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
+ assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
+ assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
+ assertNotNull(ls.getUnreservedBandwidth());
+ assertEquals(8, ls.getUnreservedBandwidth().size());
+ }
+
+ @Test
+ public void testPositiveNodes() {
+ final PathAttributesBuilder builder = new PathAttributesBuilder();
+ try {
+ this.parser.parseAttribute(NODE_ATTR, builder);
+ } catch (final BGPParsingException e) {
+ fail("No exception should occur.");
+ }
+ final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
+ final NodeAttributes ls = (NodeAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
+ assertNotNull(ls);
+
+ assertEquals("12K-2", ls.getDynamicHostname());
+ assertEquals(1, ls.getIsisAreaId().size());
+ assertArrayEquals(new byte[] { 114 }, ls.getIsisAreaId().get(0).getValue());
+ assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.linkstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.math.BigInteger;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.node.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.IsoSystemIdentifier;
+
+public class LinkstateNlriParserTest {
+
+ private final byte[] nodeNlri = new byte[] { (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x27, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+ (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+ (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39 };
+
+ private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x55, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+ (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+ (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
+ (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28,
+ (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
+ (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0,
+ (byte) 0x28 };
+
+ private final byte[] nextHop = new byte[] { (byte) 0x0a, (byte) 0x19, (byte) 0x02, (byte) 0x1b };
+
+ @Test
+ public void testNodeNlri() throws BGPParsingException {
+ final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+ final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+ parser.parseNlri(this.nodeNlri, this.nextHop, builder);
+
+ assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+ final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+ assertEquals(1, ls.getCLinkstateDestination().size());
+
+ final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+ assertEquals(NlriType.Node, dest.getNlriType());
+ assertNull(dest.getDistinguisher());
+ assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+ assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+ final LocalNodeDescriptors nodeD = dest.getLocalNodeDescriptors();
+ assertEquals(new AsNumber(72L), nodeD.getAsNumber());
+ assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), nodeD.getDomainId());
+ assertEquals(
+ new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x39 })).build()).build(), nodeD.getCRouterIdentifier());
+
+ assertNull(dest.getRemoteNodeDescriptors());
+ }
+
+ @Test
+ public void testLinkNlri() throws BGPParsingException {
+ final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+ final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+ parser.parseNlri(this.linkNlri, this.nextHop, builder);
+
+ assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+ final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+ assertEquals(1, ls.getCLinkstateDestination().size());
+
+ final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+ assertEquals(NlriType.Link, dest.getNlriType());
+ assertNull(dest.getDistinguisher());
+ assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+ assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+ final LocalNodeDescriptors local = dest.getLocalNodeDescriptors();
+ assertEquals(new AsNumber(72L), local.getAsNumber());
+ assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), local.getDomainId());
+ assertEquals(
+ new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
+ final RemoteNodeDescriptors remote = dest.getRemoteNodeDescriptors();
+ assertEquals(new AsNumber(72L), remote.getAsNumber());
+ assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), remote.getDomainId());
+ assertEquals(
+ new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x40 })).build()).build(), remote.getCRouterIdentifier());
+ final LinkDescriptors ld = dest.getLinkDescriptors();
+ assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
+ assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.linkstate;
-
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.TopologyIdentifier;
-
-public class TopologyIdentifierTest {
-
- private TopologyIdentifier identifier;
-
- @Before
- public void init() {
- this.identifier = new TopologyIdentifier(23);
- }
-
- @Test
- public void testLinkAreaIdentifier() {
- try {
- new TopologyIdentifier(4096);
- } catch (final Exception e) {
- assertTrue(e instanceof IllegalArgumentException);
- }
- try {
- new TopologyIdentifier(-2);
- } catch (final Exception e) {
- assertTrue(e instanceof IllegalArgumentException);
- }
-
- }
-
- @Test
- public void testGetId() {
- assertEquals(23, this.identifier.getValue().intValue());
- }
-
- @Test
- public void testEquals() {
- assertThat(this.identifier, not(new Object()));
-
- final TopologyIdentifier testIdentifier = new TopologyIdentifier(23);
- assertEquals(this.identifier, testIdentifier);
- }
-
- @Test
- public void testToString() {
- assertEquals("TopologyIdentifier [_value=23]", this.identifier.toString());
- final TopologyIdentifier id = new TopologyIdentifier(3);
- assertEquals("TopologyIdentifier [_value=3]", id.toString());
- }
-}
* @param error specific documented error
* @param cause cause for the error
*/
- public BGPDocumentedException(final String message, final BGPError error, final Throwable cause) {
+ public BGPDocumentedException(final String message, final BGPError error, final Exception cause) {
this(message, error, null, cause);
}
* @param data data associated with the error
* @param cause cause for the error
*/
- public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Throwable cause) {
- super(message);
+ public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Exception cause) {
+ super(message, cause);
this.error = error;
this.data = data;
logger.error("Error = " + error, this);
public static BGPDocumentedException badMessageLength(final String message, final int length) {
Preconditions.checkArgument(length >= 0 && length <= 65535);
- return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] {
- UnsignedBytes.checkedCast(length / 256), UnsignedBytes.checkedCast(length % 256) });
+ return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] { UnsignedBytes.checkedCast(length / 256),
+ UnsignedBytes.checkedCast(length % 256) });
}
}
public static BGPError forValue(final int e, final int s) {
if (e == 1) {
- if (s == 1)
+ if (s == 1) {
return BGPError.CONNECTION_NOT_SYNC;
- if (s == 2)
+ }
+ if (s == 2) {
return BGPError.BAD_MSG_LENGTH;
- if (s == 3)
+ }
+ if (s == 3) {
return BGPError.BAD_MSG_TYPE;
+ }
} else if (e == 2) {
- if (s == 0)
+ if (s == 0) {
return BGPError.UNSPECIFIC_OPEN_ERROR;
- if (s == 1)
+ }
+ if (s == 1) {
return BGPError.VERSION_NOT_SUPPORTED;
- if (s == 2)
+ }
+ if (s == 2) {
return BGPError.BAD_PEER_AS;
- if (s == 3)
+ }
+ if (s == 3) {
return BGPError.BAD_BGP_ID;
- if (s == 4)
+ }
+ if (s == 4) {
return BGPError.OPT_PARAM_NOT_SUPPORTED;
- if (s == 6)
+ }
+ if (s == 6) {
return BGPError.HOLD_TIME_NOT_ACC;
+ }
} else if (e == 3) {
- if (s == 1)
+ if (s == 1) {
return BGPError.MALFORMED_ATTR_LIST;
- if (s == 2)
+ }
+ if (s == 2) {
return BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED;
- if (s == 3)
+ }
+ if (s == 3) {
return BGPError.WELL_KNOWN_ATTR_MISSING;
- if (s == 4)
+ }
+ if (s == 4) {
return BGPError.ATTR_FLAGS_MISSING;
- if (s == 5)
+ }
+ if (s == 5) {
return BGPError.ATTR_LENGTH_ERROR;
- if (s == 6)
+ }
+ if (s == 6) {
return BGPError.ORIGIN_ATTR_NOT_VALID;
- if (s == 8)
+ }
+ if (s == 8) {
return BGPError.NEXT_HOP_NOT_VALID;
- if (s == 9)
+ }
+ if (s == 9) {
return BGPError.OPT_ATTR_ERROR;
- if (s == 10)
+ }
+ if (s == 10) {
return BGPError.NETWORK_NOT_VALID;
- if (s == 11)
+ }
+ if (s == 11) {
return BGPError.AS_PATH_MALFORMED;
- } else if (e == 4)
+ }
+ } else if (e == 4) {
return BGPError.HOLD_TIMER_EXPIRED;
- else if (e == 5)
+ } else if (e == 5) {
return BGPError.FSM_ERROR;
- else if (e == 6)
+ } else if (e == 6) {
return BGPError.CEASE;
+ }
throw new IllegalArgumentException("BGP Error code " + e + " and subcode " + s + " not recognized.");
}
}
@Override
public boolean equals(final Object obj) {
- if (obj != null && obj instanceof BgpTableTypeImpl) {
+ if (obj instanceof BgpTableTypeImpl) {
final BgpTableTypeImpl o = (BgpTableTypeImpl) obj;
return this.afi.equals(o.afi) && this.safi.equals(o.safi);
}
package org.opendaylight.protocol.bgp.parser;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.opendaylight.protocol.framework.DeserializerException;
import org.opendaylight.protocol.framework.DocumentedException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Keepalive;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.KeepaliveBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Notify;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.NotifyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
-import org.opendaylight.yangtools.yang.binding.Notification;
-
public class APITest {
}
@Test
- public void testBGPKeepAliveMessage() {
- final Notification msg = new KeepaliveBuilder().build();
- assertTrue(msg instanceof Keepalive);
- }
-
- @Test
- public void testBGPNotificationMessage() {
- final Notify msg = new NotifyBuilder().setErrorCode(BGPError.AS_PATH_MALFORMED.getCode()).setErrorSubcode(
- BGPError.AS_PATH_MALFORMED.getSubcode()).build();
- assertTrue(msg instanceof Notify);
- assertEquals(BGPError.AS_PATH_MALFORMED.getCode(), msg.getErrorCode().shortValue());
- assertEquals(BGPError.AS_PATH_MALFORMED.getSubcode(), msg.getErrorSubcode().shortValue());
- assertNull(msg.getData());
+ public void testParsingException() {
+ final DeserializerException de = new BGPParsingException("Some message");
+ assertEquals("Some message", de.getMessage());
}
@Test
- public void testBGPOpenMessage() {
- final Notification msg = new OpenBuilder().setMyAsNumber(58).setHoldTimer(5).build();
- assertNull(((Open) msg).getBgpParameters());
+ public void testBGPError() {
+ assertEquals(BGPError.BAD_MSG_TYPE, BGPError.forValue(1, 3));
}
@Test
- public void testToString() {
- final Notification o = new OpenBuilder().setMyAsNumber(58).setHoldTimer(5).build();
- final Notification n = new NotifyBuilder().setErrorCode(BGPError.AS_PATH_MALFORMED.getCode()).setErrorSubcode(
- BGPError.AS_PATH_MALFORMED.getSubcode()).build();
- assertNotSame(o.toString(), n.toString());
+ public void testTerminationReason() {
+ assertEquals(BGPError.BAD_PEER_AS.toString(), new BGPTerminationReason(BGPError.BAD_PEER_AS).getErrorMessage());
}
}
<Export-Package>
org.opendaylight.protocol.bgp.parser.impl.*
</Export-Package>
- <Activator>org.opendaylight.protocol.bgp.parser.impl.OSGiActivator</Activator>
+ <Activator>org.opendaylight.protocol.bgp.parser.impl.BundleActivator</Activator>
</instructions>
</configuration>
</plugin>
@Override
public synchronized void start(final BGPExtensionProviderContext context) {
- Preconditions.checkState(registrations == null);
+ Preconditions.checkState(this.registrations == null);
final List<AutoCloseable> regs = new ArrayList<>();
final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
final NlriRegistry nlriReg = context.getNlriRegistry();
- regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new Ipv4NlriParser()));
- regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new Ipv6NlriParser()));
+ regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
+ regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
final AttributeRegistry attrReg = context.getAttributeRegistry();
regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser()));
regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser()));
regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser()));
- regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE,
- new MultiExitDiscriminatorAttributeParser()));
+ regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, new MultiExitDiscriminatorAttributeParser()));
regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser()));
regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser()));
regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser()));
final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
// Serialization of Update message is not supported
- // regs.add(msgReg.registerMessageSerializer(Update.class, ump));
final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
- registrations = regs;
+ this.registrations = regs;
}
@Override
public synchronized void stop() {
- Preconditions.checkState(registrations != null);
+ Preconditions.checkState(this.registrations != null);
- for (AutoCloseable r : registrations) {
+ for (final AutoCloseable r : this.registrations) {
try {
r.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
logger.warn("Failed to close registration", e);
}
}
- registrations = null;
+ this.registrations = null;
}
}
* @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
*/
@Override
- public final Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException {
+ public Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException {
return this.registry.parseMessage(bytes);
}
@Override
- public final byte[] put(final Notification msg) {
+ public byte[] put(final Notification msg) {
return this.registry.serializeMessage(msg);
}
}
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.osgi.AbstractOSGiBGPExtensionProviderActivator;
-public final class OSGiActivator extends AbstractOSGiBGPExtensionProviderActivator {
+public final class BundleActivator extends AbstractOSGiBGPExtensionProviderActivator {
private final BGPExtensionProviderActivator activator = new Activator();
@Override
public class BGPKeepAliveMessageParser implements MessageParser, MessageSerializer {
public static final int TYPE = 4;
- private static final Keepalive msg = new KeepaliveBuilder().build();
- private static final byte[] bytes = MessageUtil.formatMessage(TYPE, new byte[0]);
+ private final Keepalive msg = new KeepaliveBuilder().build();
+ private final byte[] bytes = MessageUtil.formatMessage(TYPE, new byte[0]);
@Override
public Keepalive parseMessageBody(final byte[] body, final int messageLength) throws BGPDocumentedException {
if (body.length != 0) {
- throw BGPDocumentedException.badMessageLength("Message length field not within valid range.", messageLength);
+ throw BGPDocumentedException.badMessageLength("Message length field not within valid range.", messageLength);
}
-
- return msg;
+ return this.msg;
}
@Override
public byte[] serializeMessage(final Notification message) {
Preconditions.checkArgument(message instanceof Keepalive);
- return bytes;
+ return this.bytes;
}
}
private static final Logger logger = LoggerFactory.getLogger(BGPNotificationMessageParser.class);
- private static final int ERROR_SIZE = 2; // bytes
+ private static final int ERROR_SIZE = 2;
/**
* Serializes BGP Notification message.
throw new IllegalArgumentException("BGP Notification message cannot be null");
}
- final Notify ntf = (Notify)msg;
+ final Notify ntf = (Notify) msg;
logger.trace("Started serializing Notification message: {}", ntf);
final byte[] msgBody = (ntf.getData() == null) ? new byte[ERROR_SIZE] : new byte[ERROR_SIZE + ntf.getData().length];
import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
private static final int BGP_VERSION = 4;
+ private static final int AS_TRANS = 2345;
+
private final ParameterRegistry reg;
public BGPOpenMessageParser(final ParameterRegistry reg) {
if (open.getBgpParameters() != null) {
for (final BgpParameters param : open.getBgpParameters()) {
- final byte[] p = reg.serializeParameter(param);
+ final byte[] p = this.reg.serializeParameter(param);
if (p != null) {
optParams.put(p, p.length);
optParamsLength += p.length;
// When our AS number does not fit into two bytes, we report it as AS_TRANS
int openAS = open.getMyAsNumber();
- if (openAS > 65535) {
- openAS = 2345;
+ if (openAS > Util.UNSIGNED_SHORT_MAX_VALUE) {
+ openAS = AS_TRANS;
}
System.arraycopy(ByteArray.longToBytes(openAS), 6, msgBody, offset, AS_SIZE);
try {
bgpId = Ipv4Util.addressForBytes(ByteArray.subByte(body, offset, BGP_ID_SIZE));
} catch (final IllegalArgumentException e) {
- throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID);
+ throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID, e);
}
offset += BGP_ID_SIZE;
final int optLength = UnsignedBytes.toInt(body[offset]);
- List<BgpParameters> optParams = Lists.newArrayList();
+ final List<BgpParameters> optParams = Lists.newArrayList();
if (optLength > 0) {
fillParams(ByteArray.subByte(body, MIN_MSG_LENGTH, optLength), optParams);
}
final BgpParameters param;
try {
- param = reg.parseParameter(paramType, paramBody);
+ param = this.reg.parseParameter(paramType, paramBody);
} catch (final BGPParsingException e) {
throw new BGPDocumentedException("Optional parameter not parsed", BGPError.UNSPECIFIC_OPEN_ERROR, e);
}
if (totalPathAttrLength > 0) {
try {
- final PathAttributes pathAttributes = reg.parseAttributes(ByteArray.subByte(body, byteOffset,
- totalPathAttrLength));
+ final PathAttributes pathAttributes = reg.parseAttributes(ByteArray.subByte(body, byteOffset, totalPathAttrLength));
byteOffset += totalPathAttrLength;
eventBuilder.setPathAttributes(pathAttributes);
} catch (final BGPParsingException e) {
}
final List<Ipv4Prefix> nlri = Ipv4Util.prefixListForBytes(ByteArray.subByte(body, byteOffset, body.length - byteOffset));
- eventBuilder.setNlri(new NlriBuilder().setNlri(nlri).build());
-
+ if (nlri != null && !nlri.isEmpty()) {
+ eventBuilder.setNlri(new NlriBuilder().setNlri(nlri).build());
+ }
logger.trace("Update message was parsed.");
return eventBuilder.build();
}
public final class As4CapabilityHandler implements CapabilityParser, CapabilitySerializer {
public static final int CODE = 65;
+ private static final int AS4_LENGTH = 4;
+
@Override
public CParameters parseCapability(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
return new CAs4BytesBuilder().setAs4BytesCapability(
new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(bytes))).build()).build();
-
}
@Override
}
private static byte[] putAS4BytesParameterValue(final CAs4Bytes param) {
- return ByteArray.subByte(ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue()), 4, 4);
+ return ByteArray.subByte(ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue()), Long.SIZE / Byte.SIZE
+ - AS4_LENGTH, AS4_LENGTH);
}
}
\ No newline at end of file
final byte[] bytes = null;
// final GracefulCapability param = (GracefulCapability) capability;
- // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE * Byte.SIZE +
+ // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE *
+ // Byte.SIZE +
// AF_FLAGS_SIZE
// * Byte.SIZE)
// * param.getTableTypes().size())
public final class MultiProtocolCapabilityHandler implements CapabilityParser, CapabilitySerializer {
public static final int CODE = 1;
- private static final int AFI_SIZE = 2; // bytes
- private static final int SAFI_SIZE = 1; // bytes
+ private static final int AFI_SIZE = 2;
+ private static final int SAFI_SIZE = 1;
private final AddressFamilyRegistry afiReg;
private final SubsequentAddressFamilyRegistry safiReg;
@Override
public CMultiprotocol parseCapability(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
final int afiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, 0, AFI_SIZE));
- final Class<? extends AddressFamily> afi = afiReg.classForFamily(afiVal);
+ final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
if (afi == null) {
throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
}
final int safiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, AFI_SIZE + 1, SAFI_SIZE));
- final Class<? extends SubsequentAddressFamily> safi = safiReg.classForFamily(safiVal);
+ final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
if (safi == null) {
throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
}
final CMultiprotocol mp = (CMultiprotocol) capability;
final Class<? extends AddressFamily> afi = mp.getMultiprotocolCapability().getAfi();
- final Integer afival = afiReg.numberForClass(afi);
+ final Integer afival = this.afiReg.numberForClass(afi);
Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
final Class<? extends SubsequentAddressFamily> safi = mp.getMultiprotocolCapability().getSafi();
- final Integer safival = safiReg.numberForClass(safi);
+ final Integer safival = this.safiReg.numberForClass(safi);
Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
- return CapabilityUtil.formatCapability(CODE, new byte[] {
- UnsignedBytes.checkedCast(afival / 256),
- UnsignedBytes.checkedCast(afival % 256),
- 0,
- UnsignedBytes.checkedCast(safival)
- });
+ return CapabilityUtil.formatCapability(
+ CODE,
+ new byte[] { UnsignedBytes.checkedCast(afival / 256), UnsignedBytes.checkedCast(afival % 256), 0,
+ UnsignedBytes.checkedCast(safival) });
}
}
\ No newline at end of file
* the collection is a Set.
*
*/
-public class AsPathSegmentParser {
+public final class AsPathSegmentParser {
- public static final int TYPE_LENGTH = 1; // bytes
+ public static final int TYPE_LENGTH = 1;
- public static final int LENGTH_SIZE = 1; // bytes
+ public static final int LENGTH_SIZE = 1;
- public static final int AS_NUMBER_LENGTH = 4; // bytes
+ public static final int AS_NUMBER_LENGTH = 4;
/**
* Possible types of AS Path segments.
public final class ClusterIdAttributeParser implements AttributeParser {
public static final int TYPE = 10;
+ private static final int CLUSTER_LENGTH = 4;
+
@Override
public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
final List<ClusterIdentifier> list = Lists.newArrayList();
int i = 0;
while (i < bytes.length) {
- list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, 4)));
- i += 4;
+ list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, CLUSTER_LENGTH)));
+ i += CLUSTER_LENGTH;
}
builder.setClusterId(list);
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.impl.CommunityUtil;
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
/**
* Parser for Extended Communities Path Attribute.
*/
-public class CommunitiesParser {
+public final class CommunitiesParser {
- public static final int EXTENDED_COMMUNITY_LENGTH = 8; // bytes
+ public static final int EXTENDED_COMMUNITY_LENGTH = 8;
- public static final int COMMUNITY_LENGTH = 4; // bytes
+ public static final int COMMUNITY_LENGTH = 4;
- private static final int TYPE_LENGTH = 2; // bytes
+ private static final int TYPE_LENGTH = 2;
- private static final int AS_NUMBER_LENGTH = 2; // bytes
+ private static final int AS_NUMBER_LENGTH = 2;
- private static final int AS_LOCAL_ADMIN_LENGTH = 4; // bytes
+ private static final int AS_LOCAL_ADMIN_LENGTH = 4;
private CommunitiesParser() {
* @throws BGPDocumentedException if the type is not recognized
*/
@VisibleForTesting
+ // FIXME: switch to return ExtendedCommunities with setType and subtype
public static ExtendedCommunity parseExtendedCommunity(final byte[] bytes) throws BGPDocumentedException {
final int type = UnsignedBytes.toInt(bytes[0]);
final int subType = UnsignedBytes.toInt(bytes[1]);
return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else if (subType == 3) {
return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else {
return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
new AsSpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
}
- case 40: // 01000000
+ case 40:
return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
new AsSpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
case 2:
if (subType == 2) {
return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else if (subType == 3) {
return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else {
throw new BGPDocumentedException("Could not parse Extended Community subtype: " + subType, BGPError.OPT_ATTR_ERROR);
}
return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else if (subType == 3) {
return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else {
return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(
- ByteArray.subByte(value, 4, 2)).build()).build();
+ ByteArray.subByte(value, 4, 2)).build()).build();
}
- case 41: // 01000001
+ case 41:
return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
new Inet4SpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(ByteArray.subByte(value, 4, 2)).build()).build();
case 3:
return new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(value).build()).build();
- case 43: // 01000011
+ case 43:
return new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
new OpaqueExtendedCommunityBuilder().setTransitive(true).setValue(value).build()).build();
default:
* 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.parser.impl;
+package org.opendaylight.protocol.bgp.parser.impl.message.update;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.CommunitiesBuilder;
*/
public static final Community NO_EXPORT_SUBCONFED = CommunityUtil.create(0xFFFF, 0xFF03);
+ private CommunityUtil() {
+
+ }
+
/**
* Creates a new Community given AS number value and semantics using generated CommunitiesBuilder.
*
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunitiesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
import com.google.common.collect.Lists;
final List<ExtendedCommunities> set = Lists.newArrayList();
int i = 0;
while (i < bytes.length) {
- set.add((ExtendedCommunities) CommunitiesParser.parseExtendedCommunity(ByteArray.subByte(bytes, i,
- CommunitiesParser.EXTENDED_COMMUNITY_LENGTH)));
+ ExtendedCommunity comm = CommunitiesParser.parseExtendedCommunity(ByteArray.subByte(bytes, i,
+ CommunitiesParser.EXTENDED_COMMUNITY_LENGTH));
i += CommunitiesParser.EXTENDED_COMMUNITY_LENGTH;
+ set.add(new ExtendedCommunitiesBuilder().setExtendedCommunity(comm).build());
}
builder.setExtendedCommunities(set);
public final class OriginatorIdAttributeParser implements AttributeParser {
public static final int TYPE = 9;
+ private static final int ORIGINATOR_LENGTH = 4;
+
@Override
public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
- if (bytes.length != 4) {
- throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be 4, but is " + bytes.length);
+ if (bytes.length != ORIGINATOR_LENGTH) {
+ throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be " + ORIGINATOR_LENGTH + ", but is "
+ + bytes.length);
}
-
builder.setOriginatorId(bytes);
}
}
\ No newline at end of file
*/
package org.opendaylight.protocol.bgp.parser.impl;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+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.linkstate.rev130918.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.LinkstatePathAttributeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.Aggregator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AsPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AtomicAggregateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.Communities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.LocalPrefBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.MultiExitDiscBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.OriginBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.Segments;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.Nlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.WithdrawnRoutesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
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.AsPathSegment;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Metric;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@BeforeClass
public static void setUp() throws Exception {
- updateParser = new BGPUpdateMessageParser(BGPExtensionConsumerContextImpl.getSingletonInstance().getAttributeRegistry());
+ updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry());
for (int i = 1; i <= COUNTER; i++) {
final String name = "/up" + i + ".bin";
* 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testGetUpdateMessage1() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
// attributes
final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
- final List<AsPathSegment> asPath = Lists.newArrayList();
+ final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
- final Set<Community> comms = new HashSet<>();
- comms.add(CommunityUtil.NO_EXPORT);
- comms.add(CommunityUtil.NO_ADVERTISE);
- comms.add(CommunityUtil.NO_EXPORT_SUBCONFED);
- comms.add(CommunityUtil.create(0xFFFF, 0xFF10));
+ final List<Communities> comms = Lists.newArrayList();
+ comms.add((Communities) CommunityUtil.NO_EXPORT);
+ comms.add((Communities) CommunityUtil.NO_ADVERTISE);
+ comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
+ comms.add((Communities) CommunityUtil.create(0xFFFF, 0xFF10));
+
+ final UpdateBuilder builder = new UpdateBuilder();
+
+ // check nlri
+
+ final List<Ipv4Prefix> prefs = Lists.newArrayList();
+ prefs.add(new Ipv4Prefix("172.17.2.0/24"));
+ prefs.add(new Ipv4Prefix("172.17.1.0/24"));
+ prefs.add(new Ipv4Prefix("172.17.0.0/24"));
+
+ final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
+
+ assertEquals(nlri, message.getNlri());
+
+ builder.setNlri(nlri);
// check path attributes
- // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
- // true, false, false, BGPOrigin.IGP);
- // assertEquals(originAttr, attrs.get(0));
- //
- // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
- // true, false, false, asPath);
- // assertEquals(asPathAttr, attrs.get(1));
- //
- // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
- // true, false, false, nextHop);
- // assertEquals(nextHopAttr, attrs.get(2));
- //
- // final PathAttribute multiExitDisc = new PathAttribute(
- // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
- // assertEquals(multiExitDisc, attrs.get(3));
- //
- // final PathAttribute atomic = new PathAttribute(TypeCode.ATOMIC_AGGREGATE, false,
- // true, true, false, null);
- // assertEquals(atomic, attrs.get(4));
- //
- // final PathAttribute comm = new PathAttribute(TypeCode.COMMUNITIES, false,
- // true, true, false, comms);
- // assertEquals(comm, attrs.get(5));
+ final PathAttributes attrs = message.getPathAttributes();
- // check nlri
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
- // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
- // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
- // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms,
- // Collections.<ExtendedCommunity> emptySet()), nextHop);
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
- // check API message
+ paBuilder.setCNextHop(nextHop);
+ assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
+
+ paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+ assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+ paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
+ assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
+
+ paBuilder.setCommunities(comms);
+ assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
+
+ builder.setPathAttributes(paBuilder.build());
- // final Set<BGPObject> addedObjects = Sets.newHashSet();
- //
- // final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state,
- // routeState);
- //
- // addedObjects.add(route1);
- //
- // final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state,
- // routeState);
- //
- // addedObjects.add(route2);
- //
- // final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state,
- // routeState);
- //
- // addedObjects.add(route3);
+ assertEquals(builder.build(), message);
}
/*
*
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testGetUpdateMessage2() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
- // check fields
+ // check fields
assertNull(message.getWithdrawnRoutes());
+ final UpdateBuilder builder = new UpdateBuilder();
+
+ // check NLRI
+
+ final List<Ipv6Prefix> prefs = Lists.newArrayList();
+ prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
+ prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
+ prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
+
+ assertNull(message.getNlri());
+
// attributes
+
final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
- final List<AsPathSegment> asPath = Lists.newArrayList();
+ final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
- // final List<ClusterIdentifier> clusters = Lists.newArrayList(
- // new ClusterIdentifier(new byte[] { 1, 2, 3, 4}),
- // new ClusterIdentifier(new byte[] { 5, 6, 7, 8}));
+ final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new byte[] { 1, 2, 3, 4 }),
+ new ClusterIdentifier(new byte[] { 5, 6, 7, 8 }));
// check path attributes
- // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
- // true, false, false, BGPOrigin.IGP);
- // assertEquals(originAttr, attrs.get(0));
- //
- // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
- // true, false, false, asPath);
- // assertEquals(asPathAttr, attrs.get(1));
- //
- // final PathAttribute multiExitDisc = new PathAttribute(
- // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
- // assertEquals(multiExitDisc, attrs.get(2));
- //
- // final PathAttribute originatorAttr = new PathAttribute(
- // TypeCode.ORIGINATOR_ID, true, false, false, false, IPv4.FAMILY.addressForString("127.0.0.1"));
- // assertEquals(originatorAttr, attrs.get(3));
- //
- // final PathAttribute clusterAttr = new PathAttribute(
- // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
- // assertEquals(clusterAttr, attrs.get(4));
-
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
- // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath,
- // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
+ final PathAttributes attrs = message.getPathAttributes();
+
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+ paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+ assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+ paBuilder.setOriginatorId(new byte[] { 127, 0, 0, 1 });
+ assertArrayEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
+
+ paBuilder.setClusterId(clusters);
+ assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
+
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAfi(Ipv6AddressFamily.class);
+ mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+ mpBuilder.setCNextHop(nextHop);
+ mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build());
+
+ paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
+ assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
+ attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
// check API message
- // final Set<BGPObject> addedObjects = Sets.newHashSet();
- //
- // final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state,
- // routeState);
- //
- // addedObjects.add(route1);
- //
- // final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state,
- // routeState);
- //
- // addedObjects.add(route2);
- //
- // final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state,
- // routeState);
- //
- // addedObjects.add(route3);
+ builder.setPathAttributes(paBuilder.build());
+ assertEquals(builder.build(), message);
}
/*
* 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testGetUpdateMessage3() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
+ final UpdateBuilder builder = new UpdateBuilder();
+
+ // check nlri
+ final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
+
+ final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
+ builder.setNlri(new NlriBuilder().setNlri(nlri).build());
+ assertEquals(builder.getNlri(), message.getNlri());
+
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
-
final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
- final List<AsPathSegment> asPath = Lists.newArrayList();
+ final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
asPath.add(new SegmentsBuilder().setCSegment(
new CASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build());
- final BgpAggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
+ final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
new Ipv4Address("10.0.0.9")).build();
final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
- // final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.0/21");
-
// check path attributes
+ final PathAttributes attrs = message.getPathAttributes();
- // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
- // true, false, false, BGPOrigin.INCOMPLETE);
- // assertEquals(originAttr, attrs.get(0));
- //
- // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
- // true, false, false, asPath);
- // assertEquals(asPathAttr, attrs.get(1));
- //
- // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
- // true, false, false, nextHop);
- // assertEquals(nextHopAttr, attrs.get(2));
- //
- // final PathAttribute multiExitDisc = new PathAttribute(
- // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
- // assertEquals(multiExitDisc, attrs.get(3));
- //
- // final PathAttribute agg = new PathAttribute(TypeCode.AGGREGATOR, true, true,
- // false, false, aggregator);
- // assertEquals(agg, attrs.get(4));
- //
- // // check nlri
- //
- // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
- // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
- //
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
- // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath,
- // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
- // check API message
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+ paBuilder.setCNextHop(nextHop);
+ assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
+
+ paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+ assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+ paBuilder.setAggregator(aggregator);
+ assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
- // final Set<BGPObject> addedObjects = Sets.newHashSet();
- //
- // final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
- //
- // addedObjects.add(route1);
+ builder.setPathAttributes(paBuilder.build());
+
+ assertEquals(builder.build(), message);
}
/*
* 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testGetUpdateMessage4() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
- // check fields
+ final UpdateBuilder builder = new UpdateBuilder();
+ // check fields
assertNull(message.getWithdrawnRoutes());
- // attributes
+ // check nlri
+ final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
+ final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
+ final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
+
+ final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
+ builder.setNlri(new NlriBuilder().setNlri(nlri).build());
+ assertEquals(builder.getNlri(), message.getNlri());
+ // attributes
final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
- final Set<ExtendedCommunity> comms = Sets.newHashSet();
- comms.add(new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
- new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(new Ipv4Address("192.168.1.0")).setLocalAdministrator(
- new byte[] { 0x12, 0x34 }).build()).build());
+ final List<ExtendedCommunities> comms = Lists.newArrayList();
+ comms.add(new ExtendedCommunitiesBuilder().setExtendedCommunity(
+ new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
+ new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
+ new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
+
+ final List<Segments> asPath = Lists.newArrayList();
// check path attributes
+ final PathAttributes attrs = message.getPathAttributes();
- // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
- // true, false, false, BGPOrigin.EGP);
- // assertEquals(originAttr, attrs.get(0));
- //
- // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
- // true, false, false, asPath);
- // assertEquals(asPathAttr, attrs.get(1));
- //
- // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
- // true, false, false, nextHop);
- // assertEquals(nextHopAttr, attrs.get(2));
- //
- // final PathAttribute multiExitDisc = new PathAttribute(
- // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
- // assertEquals(multiExitDisc, attrs.get(3));
- //
- // final PathAttribute localPref = new PathAttribute(TypeCode.LOCAL_PREF, false,
- // true, false, false, 100);
- // assertEquals(localPref, attrs.get(4));
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
- // check nlri
- //
- // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
- // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
- // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment>
- // emptyList(), Collections.<Community> emptySet(), comms), nextHop);
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
- // check API message
+ paBuilder.setCNextHop(nextHop);
+ assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
+
+ paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+ assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+ paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+ assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
- // final Set<BGPObject> addedObjects = Sets.newHashSet();
- //
- // final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
- //
- // addedObjects.add(route1);
- //
- // final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
- //
- // addedObjects.add(route2);
- //
- // final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
- //
- // addedObjects.add(route3);
+ paBuilder.setExtendedCommunities(comms);
+ assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
+
+ // check API message
+ builder.setPathAttributes(paBuilder.build());
+ assertEquals(builder.build(), message);
}
/*
* 00 00 <- total path attribute length
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testGetUpdateMessage5() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH,
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
// attributes
-
final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
// check API message
-
final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
- assertEquals(expectedMessage.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString(),
- message.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString());
+ assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
}
/*
- * Test EOR for IPv4.
+ * End of Rib for Ipv4.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 17 <- length (23) - including header
* 01 <- value (SAFI 1)
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testEORIpv6() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
- // check fields
-
- final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
- final SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
+ final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
+ final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
assertEquals(Ipv6AddressFamily.class, afi);
- assertEquals(UnicastSubsequentAddressFamily.INSTANCE, safi);
+ assertEquals(UnicastSubsequentAddressFamily.class, safi);
}
/*
* 47 <- value (SAFI 71)
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testEORLS() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
- final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
- final SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
+ final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
+ final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
assertEquals(LinkstateAddressFamily.class, afi);
- assertEquals(LinkstateSubsequentAddressFamily.INSTANCE, safi);
+ assertEquals(LinkstateSubsequentAddressFamily.class, safi);
}
/*
00 00 01 <- value
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testBGPLink() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
+ final UpdateBuilder builder = new UpdateBuilder();
+
// check fields
assertNull(message.getWithdrawnRoutes());
- // network object state
- // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
- // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-
- // network link state
- // final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
- // container.setDefaultEntry(new IGPMetric(1));
- // final NetworkLinkState linkState = new NetworkLinkState(objState, container, null,
- // LinkProtectionType.UNPROTECTED, null, null, null);
-
- // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
- // DomainIdentifier(new byte[] { 25, 25,
- // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
- //
- // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
- // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
- // 0x0b, 0x0b, 0x0b, 0x03 })));
- // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
- //
- // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+ final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+
+ final List<Segments> asPath = Lists.newArrayList();
+
+ final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+ new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+ new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+ final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+ new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+ new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+ final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+ clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+ clBuilder.setNlriType(NlriType.Link);
+ clBuilder.setProtocolId(ProtocolId.Ospf);
+
+ final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAfi(LinkstateAddressFamily.class);
+ mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+ mpBuilder.setCNextHop(nextHop);
+
+ final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+ clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+ clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+ clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+ linkstates.add(clBuilder.build());
+
+ lsBuilder.setMpReachNlri(mpBuilder.build());
- // check API message
+ // check path attributes
+ final PathAttributes attrs = message.getPathAttributes();
+
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
- // final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
- // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
- // final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
- // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
- // final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new
- // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
- //
- // final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
- // final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
- // final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
- //
- // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1,
- // (BGPObject) link2,
- // (BGPObject) link3), Collections.<Identifier> emptySet());
- //
- // assertEquals(expectedMessage, message);
+ paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+ assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+ final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+ assertEquals(mpBuilder.getAfi(), mp.getAfi());
+ assertEquals(mpBuilder.getSafi(), mp.getSafi());
+ assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+ final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+ dBuilder.setCLinkstateDestination(linkstates);
+
+ mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+ lsBuilder.setMpReachNlri(mpBuilder.build());
+
+ paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder();
+
+ lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
+ new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
+ paBuilder.addAugmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class,
+ lsAttrBuilder.build());
+
+ assertEquals(
+ lsAttrBuilder.build().getLinkstatePathAttribute(),
+ attrs.getAugmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class).getLinkstatePathAttribute());
+
+ final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+ assertEquals(linkstates.size(), dests.size());
+
+ assertEquals(linkstates, dests);
+ // check API message
+ builder.setPathAttributes(paBuilder.build());
+ assertEquals(builder.build(), message);
}
/*
04 <- next hop length
19 19 19 01 - nexthop (25.25.25.1)
00 <- reserved
+
00 01 <- NLRI type (1 - nodeNLRI)
00 31 <- NLRI length (49)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
-
01 00 <- local node descriptor type (256)
00 24 <- length (36)
02 00 <- node descriptor type (member AS - 512)
00 2d <- NLRI length (45)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
-
01 00 <- local node descriptor type (256)
00 20 <- length (32)
02 00 <- node descriptor type (member AS - 512)
00 00 00 64 <- value
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testBGPNode() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
+ final UpdateBuilder builder = new UpdateBuilder();
+
// check fields
assertNull(message.getWithdrawnRoutes());
- // network object state
- // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
- // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
- // final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(),
- // Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier>
- // emptySet(), null);
-
- // network link state
-
- // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
- // DomainIdentifier(new byte[] { 25, 25,
- // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
- //
- // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
- // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
- // 0x0b, 0x0b, 0x0b, 0x03 })));
- // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
- //
- // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+ // attributes
- // check API message
+ final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+
+ final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+ new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+ new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+ final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+ clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+ clBuilder.setNlriType(NlriType.Node);
+ clBuilder.setProtocolId(ProtocolId.Ospf);
+
+ final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+ linkstates.add(clBuilder.build());
+
+ final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAfi(LinkstateAddressFamily.class);
+ mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+ mpBuilder.setCNextHop(nextHop);
+
+ final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+ dBuilder.setCLinkstateDestination(linkstates);
+
+ mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+ lsBuilder.setMpReachNlri(mpBuilder.build());
+
+ final List<Segments> asPath = Lists.newArrayList();
- // final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
- // final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
- // final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
- //
- // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1,
- // (BGPObject) node2,
- // (BGPObject) node3), Collections.<Identifier> emptySet());
- //
- // assertEquals(expectedMessage, message);
+ // check path attributes
+ final PathAttributes attrs = message.getPathAttributes();
+
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+ paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+ assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+ paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+ final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+ assertEquals(mpBuilder.getAfi(), mp.getAfi());
+ assertEquals(mpBuilder.getSafi(), mp.getSafi());
+ assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+ final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+ assertEquals(linkstates.size(), dests.size());
+
+ assertEquals(linkstates, dests);
+
+ // check API message
+ builder.setPathAttributes(paBuilder.build());
+ assertEquals(builder.build(), message);
}
/*
*/
@Test
public void testOpenMessage() throws Exception {
- final MessageRegistry msgReg = BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
final Open open = (Open) msgReg.parseMessage(inputBytes.get(13));
final Set<BgpTableType> types = Sets.newHashSet();
for (final BgpParameters param : open.getBgpParameters()) {
import org.junit.Ignore;
import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
public class CommunityTest {
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.fail;
-import java.io.IOException;
import java.util.Map;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesParser;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.framework.DeserializerException;
import org.opendaylight.protocol.framework.DocumentedException;
import org.opendaylight.protocol.util.ByteList;
assertEquals(40, ((CAs4Bytes) tlv4).getAs4BytesCapability().getAsNumber().getValue().longValue());
- // FIXME: no generated toString
- // assertEquals(new As4BytesBuilder().setCAs4Bytes(new CAs4BytesBuilder().setAsNumber(new AsNumber((long)
- // 40)).build()).build().toString(), tlv4.toString());
+ assertEquals(
+ new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build(),
+ tlv4);
}
@Test
}
@Test
- public void testBGPHeaderParser() throws IOException {
- final MessageRegistry msgReg = BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+ public void testBGPHeaderParser() throws Exception {
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
try {
msgReg.parseMessage(new byte[] { (byte) 0, (byte) 0 });
fail("Exception should have occured.");
}
@Test
- public void testMessageParser() throws IOException {
- final MessageRegistry msgReg = BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+ public void testMessageParser() throws Exception {
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
String ex = "";
try {
msgReg.serializeMessage(null);
--- /dev/null
+/*
+ * Copyright (c) 2013 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.parser.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
+
+import com.google.common.collect.Lists;
+
+public class OpenTest {
+
+ private final byte[] result = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x25, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x1e, (byte) 0x00, (byte) 0x03, (byte) 0x7f,
+ (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x02, (byte) 0x06, (byte) 0x41, (byte) 0x04, (byte) 0x00,
+ (byte) 0x00, (byte) 0x03, (byte) 0xe8 };
+
+ @Test
+ public void testSerializeOpen() throws Exception {
+ final List<BgpParameters> tlvs = Lists.newArrayList();
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build()).build()).build());
+ final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30).setHoldTimer(3).setVersion(
+ new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
+ final byte[] msg = new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getParameterRegistry()).serializeMessage(open);
+ assertArrayEquals(this.result, msg);
+ }
+}
* 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.rib.impl;
+package org.opendaylight.protocol.bgp.parser.impl;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.Map;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.framework.DeserializerException;
import org.opendaylight.protocol.framework.DocumentedException;
import org.opendaylight.protocol.util.ByteArray;
public class ParserTest {
public static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
- (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
+ (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
public static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
public static final byte[] openWithCpblt1 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
- (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
- (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
- (byte) 0x04, (byte) 0x00, (byte) 0x47 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+ (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+ (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
+ (byte) 0x04, (byte) 0x00, (byte) 0x47 };
public static final byte[] openWithCpblt2 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
- (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
- (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
- (byte) 0x01, (byte) 0x00, (byte) 0x01 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+ (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+ (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
+ (byte) 0x01, (byte) 0x00, (byte) 0x01 };
- final MessageRegistry factory =
- BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+ static BGPMessageFactory factory;
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ factory = new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry());
+ }
@Test
public void testHeaderErrors() throws DeserializerException, DocumentedException {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00 };
wrong = ByteArray.cutBytes(wrong, 16);
try {
- this.factory.parseMessage(wrong);
+ ParserTest.factory.parse(wrong);
fail("Exception should have occcured.");
} catch (final IllegalArgumentException e) {
assertEquals("Too few bytes in passed array. Passed: " + wrong.length + ". Expected: >= 19.", e.getMessage());
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0x00, (byte) 0x13, (byte) 0x08 };
try {
- this.factory.parseMessage(bytes);
+ ParserTest.factory.parse(bytes);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals(BGPError.BAD_MSG_TYPE, ((BGPDocumentedException) e).getError());
@Test
public void testKeepAliveMsg() throws DeserializerException, DocumentedException {
final Notification keepAlive = new KeepaliveBuilder().build();
- final byte[] bytes = this.factory.serializeMessage(keepAlive);
+ final byte[] bytes = ParserTest.factory.put(keepAlive);
assertArrayEquals(keepAliveBMsg, bytes);
- final Notification m = this.factory.parseMessage(bytes);
+ final Notification m = ParserTest.factory.parse(bytes);
assertTrue(m instanceof Keepalive);
}
(byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05 };
try {
- this.factory.parseMessage(bytes);
+ ParserTest.factory.parse(bytes);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertThat(e.getMessage(), containsString("Message length field not within valid range."));
public void testOpenMessage() throws UnknownHostException, DeserializerException, DocumentedException {
final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(
new ProtocolVersion((short) 4)).build();
- final byte[] bytes = this.factory.serializeMessage(open);
+ final byte[] bytes = ParserTest.factory.put(open);
assertArrayEquals(openBMsg, bytes);
- final Notification m = this.factory.parseMessage(bytes);
+ final Notification m = ParserTest.factory.parse(bytes);
assertTrue(m instanceof Open);
assertEquals(100, ((Open) m).getMyAsNumber().intValue());
(byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parse(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("Hold time value not acceptable.", e.getMessage());
(byte) 0xff, (byte) 0xff };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parse(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("Open message too small.", e.getMessage());
(byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parse(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("BGP Protocol version 8 not supported.", e.getMessage());
public void testNotificationMsg() throws DeserializerException, DocumentedException {
Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
- byte[] bytes = this.factory.serializeMessage(notMsg);
+ byte[] bytes = ParserTest.factory.put(notMsg);
assertArrayEquals(notificationBMsg, bytes);
- Notification m = this.factory.parseMessage(bytes);
+ Notification m = ParserTest.factory.parse(bytes);
assertTrue(m instanceof Notify);
assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(
BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
- bytes = this.factory.serializeMessage(notMsg);
+ bytes = ParserTest.factory.put(notMsg);
- m = this.factory.parseMessage(bytes);
+ m = ParserTest.factory.parse(bytes);
assertTrue(m instanceof Notify);
assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
(byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02 };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parse(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("Notification message too small.", e.getMessage());
(byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parse(bMsg);
fail("Exception should have occured.");
} catch (final IllegalArgumentException e) {
assertEquals("BGP Error code 2 and subcode 170 not recognized.", e.getMessage());
final Open open = new OpenBuilder().setMyAsNumber(72).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("172.20.160.170")).setVersion(
new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
- final byte[] result = this.factory.serializeMessage(open);
+ final byte[] result = ParserTest.factory.put(open);
// the capabilities can be swapped.
assertTrue(Arrays.equals(openWithCpblt1, result) || Arrays.equals(openWithCpblt2, result));
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
/*
* To test incorrect values.
*/
public class PathAttributeParserTest {
@Test
- public void testOriginParser() {
+ public void testOriginParser() throws Exception {
try {
- BGPExtensionConsumerContextImpl.getSingletonInstance().getAttributeRegistry().parseAttributes(new byte[] { 0x40, 0x01, 0x01, 0x04 });
+ ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry().parseAttributes(new byte[] { 0x40, 0x01, 0x01, 0x04 });
fail("This needs to fail.");
} catch (final BGPDocumentedException e) {
assertEquals("Unknown Origin type.", e.getMessage());
package org.opendaylight.protocol.bgp.parser.mock;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Set;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.framework.DeserializerException;
import org.opendaylight.protocol.framework.DocumentedException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+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.message.rev130918.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AsPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.OriginBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.Segments;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.c.multiprotocol.MultiprotocolCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Lists;
* @throws IOException
*/
@Test
- @Ignore
- // FIXME : BUG-94
public void testGetUpdateMessage() throws DeserializerException, DocumentedException, IOException {
final Map<byte[], Notification> updateMap = Maps.newHashMap();
for (int i = 0; i < this.inputBytes.length; i++) {
for (int i = 0; i < this.inputBytes.length; i++) {
assertEquals(this.messages.get(i), mockParser.parse(this.inputBytes[i]));
}
- // assertThat(this.messages.get(3), not(mockParser.parse(this.inputBytes[8]).get(0)));
+ assertNotSame(this.messages.get(3), mockParser.parse(this.inputBytes[8]));
}
/**
*/
private Update fillMessages(final long asn) throws UnknownHostException {
- // FIXME: to be fixed in testing phase
- /*final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(asn)).build());
- final List<AsPathSegment> asPath = Lists.newArrayList();
+ final UpdateBuilder builder = new UpdateBuilder();
+
+ final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(asn)).build());
+ final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
- final CNextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
+ final CNextHop nextHop = (CNextHop) new CIpv6NextHopBuilder().setIpv6NextHop(
new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
- final Prefix<IPv6Address> pref1 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:1:2::")), 64);
- final Prefix<IPv6Address> pref2 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:1:1::")), 64);
- final Prefix<IPv6Address> pref3 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:1::")), 64);
+ final Ipv6Prefix pref1 = new Ipv6Prefix("2001:db8:1:2::/64");
+ final Ipv6Prefix pref2 = new Ipv6Prefix("2001:db8:1:1::/64");
+ final Ipv6Prefix pref3 = new Ipv6Prefix("2001:db8:1::/64");
- final Set<BGPObject> addedObjects = new HashSet<BGPObject>();
+ PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
- final NetworkRouteState nstate = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
- final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
+ MpReachNlriBuilder mpReachBuilder = new MpReachNlriBuilder();
+ mpReachBuilder.setAfi(Ipv6AddressFamily.class);
+ mpReachBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+ mpReachBuilder.setCNextHop(nextHop);
+ mpReachBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(pref1, pref2, pref3)).build()).build());
- final BGPRoute route1 = new BGPIPv6RouteImpl(pref1, state, nstate);
- final BGPRoute route2 = new BGPIPv6RouteImpl(pref2, state, nstate);
- final BGPRoute route3 = new BGPIPv6RouteImpl(pref3, state, nstate);
- addedObjects.add(route1);
- addedObjects.add(route2);
- addedObjects.add(route3);
+ paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpReachBuilder.build()).build());
- return new BGPUpdateMessageImpl(addedObjects, Collections.<Identifier> emptySet());*/
+ builder.setPathAttributes(paBuilder.build());
- return new UpdateBuilder().build();
+ return builder.build();
}
@Test
public final class CapabilityUtil {
- public static final int CODE_SIZE = 1; // bytes
- public static final int LENGTH_SIZE = 1; // bytes
- private static final int HEADER_SIZE = CODE_SIZE + LENGTH_SIZE;
+ private static final int HEADER_SIZE = 2;
private CapabilityUtil() {
import com.google.common.primitives.UnsignedBytes;
-
public final class MessageUtil {
- public static final int LENGTH_FIELD_LENGTH = 2; // bytes
- public static final int MARKER_LENGTH = 16; // bytes
- public static final int TYPE_FIELD_LENGTH = 1; // bytes
+ public static final int LENGTH_FIELD_LENGTH = 2;
+ public static final int MARKER_LENGTH = 16;
+ public static final int TYPE_FIELD_LENGTH = 1;
public static final int COMMON_HEADER_LENGTH = LENGTH_FIELD_LENGTH + TYPE_FIELD_LENGTH + MARKER_LENGTH;
private MessageUtil() {
public static byte[] formatMessage(final int type, final byte[] body) {
final byte[] retBytes = new byte[COMMON_HEADER_LENGTH + body.length];
- Arrays.fill(retBytes, 0, MARKER_LENGTH, (byte) 0xff);
- System.arraycopy(ByteArray.intToBytes(body.length + COMMON_HEADER_LENGTH),
- Integer.SIZE / Byte.SIZE - LENGTH_FIELD_LENGTH,
+ Arrays.fill(retBytes, 0, MARKER_LENGTH, UnsignedBytes.MAX_VALUE);
+ System.arraycopy(ByteArray.intToBytes(body.length + COMMON_HEADER_LENGTH), Integer.SIZE / Byte.SIZE - LENGTH_FIELD_LENGTH,
retBytes, MARKER_LENGTH, LENGTH_FIELD_LENGTH);
retBytes[MARKER_LENGTH + LENGTH_FIELD_LENGTH] = UnsignedBytes.checkedCast(type);
public interface NlriRegistry {
public MpUnreachNlri parseMpUnreach(final byte[] bytes) throws BGPParsingException;
+
public MpReachNlri parseMpReach(final byte[] bytes) throws BGPParsingException;
- // public byte[] serializeNlri(DataObject attribute);
}
public final class NlriUtil {
private NlriUtil() {
-
}
public static void parseNextHop(final byte[] bytes, final MpReachNlriBuilder builder) throws BGPParsingException {
final CNextHop addr;
switch (bytes.length) {
- case 4:
+ case Ipv4Util.IP4_LENGTH:
addr = new CIpv4NextHopBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(Ipv4Util.addressForBytes(bytes)).build()).build();
break;
- case 16:
+ case Ipv6Util.IPV6_LENGTH:
addr = new CIpv6NextHopBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(bytes)).build()).build();
break;
- case 32:
+ case Ipv6Util.IPV6_LENGTH * 2:
addr = new CIpv6NextHopBuilder().setIpv6NextHop(
- new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 0, 16))).setLinkLocal(
- Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 16, 16))).build()).build();
+ new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 0, Ipv6Util.IPV6_LENGTH))).setLinkLocal(
+ Ipv6Util.addressForBytes(ByteArray.subByte(bytes, Ipv6Util.IPV6_LENGTH, Ipv6Util.IPV6_LENGTH))).build()).build();
break;
default:
throw new BGPParsingException("Cannot parse NEXT_HOP attribute. Wrong bytes length: " + bytes.length);
import com.google.common.primitives.UnsignedBytes;
public final class ParameterUtil {
+
+ private static final int HEADER_SIZE = 2;
+
private ParameterUtil() {
}
public static byte[] formatParameter(final int type, final byte[] value) {
- final byte[] bytes = new byte[2 + value.length];
+ final byte[] bytes = new byte[HEADER_SIZE + value.length];
bytes[0] = UnsignedBytes.checkedCast(type);
bytes[1] = UnsignedBytes.checkedCast(value.length);
- System.arraycopy(value, 0, bytes, 2, value.length);
+ System.arraycopy(value, 0, bytes, HEADER_SIZE, value.length);
return bytes;
}
}
import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
import org.opendaylight.protocol.concepts.AbstractRegistration;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import com.google.common.base.Preconditions;
class OSGiBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
+ protected final SimpleBGPExtensionProviderContext providerContext = new SimpleBGPExtensionProviderContext();
protected final BundleContext bundleContext;
OSGiBGPExtensionConsumerContext(final BundleContext context) {
this.bundleContext = Preconditions.checkNotNull(context);
}
- protected <T> AutoCloseable register(final Class<T> clazz, final T object) {
+ protected final <T> AutoCloseable register(final Class<T> clazz, final T object) {
final ServiceRegistration<T> reg = bundleContext.registerService(clazz, object, null);
return new AbstractRegistration() {
};
}
- public BundleContext getBundleContext() {
+ public final BundleContext getBundleContext() {
return bundleContext;
}
@Override
- public AddressFamilyRegistry getAddressFamilyRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final AddressFamilyRegistry getAddressFamilyRegistry() {
+ return providerContext.getAddressFamilyRegistry();
}
@Override
- public AttributeRegistry getAttributeRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final AttributeRegistry getAttributeRegistry() {
+ return providerContext.getAttributeRegistry();
}
@Override
- public CapabilityRegistry getCapabilityRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final CapabilityRegistry getCapabilityRegistry() {
+ return providerContext.getCapabilityRegistry();
}
@Override
- public MessageRegistry getMessageRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final MessageRegistry getMessageRegistry() {
+ return providerContext.getMessageRegistry();
}
@Override
- public NlriRegistry getNlriRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final NlriRegistry getNlriRegistry() {
+ return providerContext.getNlriRegistry();
}
@Override
- public ParameterRegistry getParameterRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final ParameterRegistry getParameterRegistry() {
+ return providerContext.getParameterRegistry();
}
@Override
- public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+ return providerContext.getSubsequentAddressFamilyRegistry();
}
-
}
private final static Logger logger = LoggerFactory.getLogger(AbstractMessageRegistry.class);
protected abstract Notification parseBody(final int type, final byte[] body, final int messageLength) throws BGPDocumentedException;
+
protected abstract byte[] serializeMessageImpl(final Notification message);
@Override
throw new IllegalArgumentException("Too few bytes in passed array. Passed: " + bytes.length + ". Expected: >= "
+ MessageUtil.COMMON_HEADER_LENGTH + ".");
}
- /*
- * byte array starts with message length
- */
- // final byte[] ones = new byte[MARKER_LENGTH];
- // Arrays.fill(ones, (byte)0xff);
- // if (Arrays.equals(bytes, ones))
+ final byte[] marker = ByteArray.subByte(bytes, 0, MessageUtil.MARKER_LENGTH);
+ final byte[] ones = new byte[MessageUtil.MARKER_LENGTH];
+ Arrays.fill(ones, (byte) 0xff);
+ // TODO: possible refactor
+ // if (Arrays.equals(marker, ones)) {
// throw new BGPDocumentedException("Marker not set to ones.", BGPError.CONNECTION_NOT_SYNC);
+ // }
final byte[] bs = ByteArray.cutBytes(bytes, MessageUtil.MARKER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(bs, 0, MessageUtil.LENGTH_FIELD_LENGTH));
final int messageType = UnsignedBytes.toInt(bs[MessageUtil.LENGTH_FIELD_LENGTH]);
--- /dev/null
+/*
+ * Copyright (c) 2013 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.parser.spi.pojo;
+
+import java.util.ServiceLoader;
+
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+
+public final class ServiceLoaderBGPExtensionProviderContext {
+ private ServiceLoaderBGPExtensionProviderContext() {
+
+ }
+
+ public static BGPExtensionConsumerContext createConsumerContext() throws Exception {
+ final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
+
+ final ServiceLoader<BGPExtensionProviderActivator> loader = ServiceLoader.load(BGPExtensionProviderActivator.class);
+ for (BGPExtensionProviderActivator a : loader) {
+ a.start(ctx);
+ }
+
+ return ctx;
+ }
+}
package org.opendaylight.protocol.bgp.parser.spi.pojo;
import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
import com.google.common.base.Preconditions;
final class SimpleAddressFamilyRegistry extends AbstractFamilyRegistry<AddressFamily, Integer> implements AddressFamilyRegistry {
AutoCloseable registerAddressFamily(final Class<? extends AddressFamily> clazz, final int number) {
- Preconditions.checkArgument(number >= 0 && number <= 65535);
+ Preconditions.checkArgument(number >= 0 && number <= Util.UNSIGNED_SHORT_MAX_VALUE);
return super.registerFamily(clazz, number);
}
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
import org.opendaylight.yangtools.yang.binding.DataContainer;
private final HandlerRegistry<DataContainer, AttributeParser, AttributeSerializer> handlers = new HandlerRegistry<>();
AutoCloseable registerAttributeParser(final int attributeType, final AttributeParser parser) {
- Preconditions.checkArgument(attributeType >= 0 && attributeType <= 255);
- return handlers.registerParser(attributeType, parser);
+ Preconditions.checkArgument(attributeType >= 0 && attributeType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+ return this.handlers.registerParser(attributeType, parser);
}
AutoCloseable registerAttributeSerializer(final Class<? extends DataObject> paramClass, final AttributeSerializer serializer) {
- return handlers.registerSerializer(paramClass, serializer);
+ return this.handlers.registerSerializer(paramClass, serializer);
}
- private int parseAttribute( final byte[] bytes, final int offset, final PathAttributesBuilder builder)
- throws BGPDocumentedException, BGPParsingException {
+ private int parseAttribute(final byte[] bytes, final int offset, final PathAttributesBuilder builder) throws BGPDocumentedException,
+ BGPParsingException {
// FIXME: validate minimum length
final boolean[] flags = ByteArray.parseBits(bytes[offset]);
final int type = UnsignedBytes.toInt(bytes[offset + 1]);
hdrlen = 3;
}
- final AttributeParser parser = handlers.getParser(type);
+ final AttributeParser parser = this.handlers.getParser(type);
if (parser == null) {
if (!flags[0]) {
throw new BGPDocumentedException("Well known attribute not recognized.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
@Override
public byte[] serializeAttribute(final DataObject attribute) {
- final AttributeSerializer serializer = handlers.getSerializer(attribute.getImplementedInterface());
+ final AttributeSerializer serializer = this.handlers.getSerializer(attribute.getImplementedInterface());
if (serializer == null) {
return null;
}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.parser.spi.pojo;
+
+import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+
+class SimpleBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
+ protected final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
+ protected final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
+ protected final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
+ protected final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
+ protected final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
+ protected final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
+ protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(this.afiReg, this.safiReg);
+
+ @Override
+ public final AddressFamilyRegistry getAddressFamilyRegistry() {
+ return this.afiReg;
+ }
+
+ @Override
+ public final AttributeRegistry getAttributeRegistry() {
+ return this.attrReg;
+ }
+
+ @Override
+ public final CapabilityRegistry getCapabilityRegistry() {
+ return this.capReg;
+ }
+
+ @Override
+ public final MessageRegistry getMessageRegistry() {
+ return this.msgReg;
+ }
+
+ @Override
+ public final NlriRegistry getNlriRegistry() {
+ return this.nlriReg;
+ }
+
+ @Override
+ public final ParameterRegistry getParameterRegistry() {
+ return this.paramReg;
+ }
+
+ @Override
+ public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+ return this.safiReg;
+ }
+}
*/
package org.opendaylight.protocol.bgp.parser.spi.pojo;
-import java.util.ServiceLoader;
-
-import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
-import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
-import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
import org.opendaylight.protocol.bgp.parser.spi.ParameterParser;
-import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
import org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer;
-import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Notification;
-public final class BGPExtensionConsumerContextImpl implements BGPExtensionProviderContext {
- private static final class Holder {
- private static final BGPExtensionConsumerContext INSTANCE;
-
- static {
- try {
- INSTANCE = BGPExtensionConsumerContextImpl.create();
- } catch (Exception e) {
- throw new ExceptionInInitializerError(e);
- }
- }
- }
-
- private final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
- private final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
- private final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
- private final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
- private final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
- private final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
- private final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(afiReg, safiReg);
-
- private BGPExtensionConsumerContextImpl() {
-
- }
-
- public static BGPExtensionConsumerContext getSingletonInstance() {
- return Holder.INSTANCE;
- }
-
- public static BGPExtensionConsumerContext create() throws Exception {
- final BGPExtensionConsumerContextImpl ctx = new BGPExtensionConsumerContextImpl();
-
- final ServiceLoader<BGPExtensionProviderActivator> loader = ServiceLoader.load(BGPExtensionProviderActivator.class);
- for (BGPExtensionProviderActivator a : loader) {
- a.start(ctx);
- }
-
- return ctx;
- }
-
- @Override
- public AddressFamilyRegistry getAddressFamilyRegistry() {
- return afiReg;
- }
-
+public final class SimpleBGPExtensionProviderContext extends SimpleBGPExtensionConsumerContext implements BGPExtensionProviderContext {
@Override
public AutoCloseable registerAddressFamily(final Class<? extends AddressFamily> clazz, final int number) {
return afiReg.registerAddressFamily(clazz, number);
}
- @Override
- public AttributeRegistry getAttributeRegistry() {
- return attrReg;
- }
-
@Override
public AutoCloseable registerAttributeParser(final int attributeType, final AttributeParser parser) {
return attrReg.registerAttributeParser(attributeType, parser);
return attrReg.registerAttributeSerializer(attributeClass, serializer);
}
- @Override
- public CapabilityRegistry getCapabilityRegistry() {
- return capReg;
- }
-
@Override
public AutoCloseable registerCapabilityParser(final int capabilityType, final CapabilityParser parser) {
return capReg.registerCapabilityParser(capabilityType, parser);
return capReg.registerCapabilitySerializer(capabilityClass, serializer);
}
- @Override
- public MessageRegistry getMessageRegistry() {
- return msgReg;
- }
-
@Override
public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
return msgReg.registerMessageParser(messageType, parser);
return msgReg.registerMessageSerializer(messageClass, serializer);
}
- @Override
- public NlriRegistry getNlriRegistry() {
- return nlriReg;
- }
-
@Override
public AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi,
final NlriParser parser) {
throw new UnsupportedOperationException("NLRI serialization not implemented");
}
- @Override
- public ParameterRegistry getParameterRegistry() {
- return paramReg;
- }
-
@Override
public AutoCloseable registerParameterParser(final int parameterType, final ParameterParser parser) {
return paramReg.registerParameterParser(parameterType, parser);
return paramReg.registerParameterSerializer(paramClass, serializer);
}
- @Override
- public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
- return safiReg;
- }
-
@Override
public AutoCloseable registerSubsequentAddressFamily(final Class<? extends SubsequentAddressFamily> clazz, final int number) {
return safiReg.registerSubsequentAddressFamily(clazz, number);
import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
import org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
import org.opendaylight.yangtools.yang.binding.DataContainer;
private final HandlerRegistry<DataContainer, CapabilityParser, CapabilitySerializer> handlers = new HandlerRegistry<>();
AutoCloseable registerCapabilityParser(final int messageType, final CapabilityParser parser) {
- Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
- return handlers.registerParser(messageType, parser);
+ Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+ return this.handlers.registerParser(messageType, parser);
}
AutoCloseable registerCapabilitySerializer(final Class<? extends CParameters> paramClass, final CapabilitySerializer serializer) {
- return handlers.registerSerializer(paramClass, serializer);
+ return this.handlers.registerSerializer(paramClass, serializer);
}
@Override
public CParameters parseCapability(final int type, final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
- final CapabilityParser parser = handlers.getParser(type);
+ final CapabilityParser parser = this.handlers.getParser(type);
if (parser == null) {
return null;
}
@Override
public byte[] serializeCapability(final CParameters capability) {
- final CapabilitySerializer serializer = handlers.getSerializer(capability.getImplementedInterface());
+ final CapabilitySerializer serializer = this.handlers.getSerializer(capability.getImplementedInterface());
if (serializer == null) {
return null;
}
import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
import org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer;
import org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
import org.opendaylight.yangtools.yang.binding.DataContainer;
private final HandlerRegistry<DataContainer, ParameterParser, ParameterSerializer> handlers = new HandlerRegistry<>();
AutoCloseable registerParameterParser(final int messageType, final ParameterParser parser) {
- Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
- return handlers.registerParser(messageType, parser);
+ Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+ return this.handlers.registerParser(messageType, parser);
}
AutoCloseable registerParameterSerializer(final Class<? extends BgpParameters> paramClass, final ParameterSerializer serializer) {
- return handlers.registerSerializer(paramClass, serializer);
+ return this.handlers.registerSerializer(paramClass, serializer);
}
@Override
public BgpParameters parseParameter(final int parameterType, final byte[] bytes) throws BGPParsingException, BGPDocumentedException {
- final ParameterParser parser = handlers.getParser(parameterType);
+ final ParameterParser parser = this.handlers.getParser(parameterType);
if (parser == null) {
return null;
}
@Override
public byte[] serializeParameter(final BgpParameters parameter) {
- final ParameterSerializer serializer = handlers.getSerializer(parameter.getImplementedInterface());
+ final ParameterSerializer serializer = this.handlers.getSerializer(parameter.getImplementedInterface());
if (serializer == null) {
return null;
}
package org.opendaylight.protocol.bgp.parser.spi.pojo;
import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
import com.google.common.base.Preconditions;
-final class SimpleSubsequentAddressFamilyRegistry extends AbstractFamilyRegistry<SubsequentAddressFamily, Integer> implements SubsequentAddressFamilyRegistry {
+final class SimpleSubsequentAddressFamilyRegistry extends AbstractFamilyRegistry<SubsequentAddressFamily, Integer> implements
+ SubsequentAddressFamilyRegistry {
AutoCloseable registerSubsequentAddressFamily(final Class<? extends SubsequentAddressFamily> clazz, final int number) {
- Preconditions.checkArgument(number >= 0 && number <= 255);
+ Preconditions.checkArgument(number >= 0 && number <= Util.UNSIGNED_BYTE_MAX_VALUE);
return super.registerFamily(clazz, number);
}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.parser.spi;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHop;
+
+import com.google.common.primitives.UnsignedBytes;
+
+public class UtilsTest {
+
+ @Test
+ public void testCapabilityUtil() {
+ final byte[] result = new byte[] { 1, 2, 4, 8 };
+ assertArrayEquals(result, CapabilityUtil.formatCapability(1, new byte[] { 4, 8 }));
+ }
+
+ @Test
+ public void testMessageUtil() {
+ final byte[] result = new byte[] { UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+ UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+ UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+ UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+ UnsignedBytes.MAX_VALUE, 0, 23, 3, 32, 5, 14, 21 };
+ assertArrayEquals(result, MessageUtil.formatMessage(3, new byte[] { 32, 5, 14, 21 }));
+ }
+
+ @Test
+ public void testNlriUtil() {
+ final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+ final byte[] ipv4 = new byte[] { 42, 42, 42, 42 };
+ try {
+ NlriUtil.parseNextHop(ipv4, builder);
+ } catch (final BGPParsingException e) {
+ fail("This exception should not happen");
+ }
+ CNextHop hop = builder.getCNextHop();
+ assertEquals("42.42.42.42", ((CIpv4NextHop) hop).getIpv4NextHop().getGlobal().getValue());
+
+ final byte[] ipv6 = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 01 };
+ try {
+ NlriUtil.parseNextHop(ipv6, builder);
+ } catch (final BGPParsingException e) {
+ fail("This exception should not happen");
+ }
+ hop = builder.getCNextHop();
+ assertEquals("2001:db8::1", ((CIpv6NextHop) hop).getIpv6NextHop().getGlobal().getValue());
+ assertNull(((CIpv6NextHop) hop).getIpv6NextHop().getLinkLocal());
+
+ final byte[] ipv6l = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
+ 01, (byte) 0xfe, (byte) 0x80, 00, 00, 00, 00, 00, 00, (byte) 0xc0, 01, 0x0b, (byte) 0xff, (byte) 0xfe, 0x7e, 00, 00 };
+ try {
+ NlriUtil.parseNextHop(ipv6l, builder);
+ } catch (final BGPParsingException e) {
+ fail("This exception should not happen");
+ }
+ hop = builder.getCNextHop();
+ assertEquals("2001:db8::1", ((CIpv6NextHop) hop).getIpv6NextHop().getGlobal().getValue());
+ assertEquals("fe80::c001:bff:fe7e:0", ((CIpv6NextHop) hop).getIpv6NextHop().getLinkLocal().getValue());
+
+ final byte[] wrong = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d };
+ try {
+ NlriUtil.parseNextHop(wrong, builder);
+ fail("Exception should happen");
+ } catch (final BGPParsingException e) {
+ assertEquals("Cannot parse NEXT_HOP attribute. Wrong bytes length: 3", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterUtil() {
+ final byte[] result = new byte[] { 1, 2, 4, 8 };
+ assertArrayEquals(result, ParameterUtil.formatParameter(1, new byte[] { 4, 8 }));
+ }
+}
namespace "urn:opendaylight:params:xml:ns:yang:bgp-rib";
prefix "rib";
- import bgp-types { prefix bgp-t; revision-date 2013-09-19; }
import bgp-message { prefix bgp-msg; revision-date 2013-09-18; }
import bgp-multiprotocol { prefix bgp-mp; revision-date 2013-09-18; }
import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
}
choice routes {
- list ipv4-routes {
- when "../../afi = ipv4";
+ case ipv4-routes {
+ list ipv4-routes {
+ when "../../afi = ipv4";
- leaf prefix {
- type inet:ipv4-prefix;
- }
- key prefix;
-
- uses route;
- }
- list ipv6-routes {
- when "../../afi = ipv6";
-
- leaf prefix {
- type inet:ipv6-prefix;
- }
- key prefix;
-
- uses route;
- }
- case linkstate-routes {
- list linkstate-links {
- // FIXME: fill this out
+ leaf prefix {
+ type inet:ipv4-prefix;
+ }
+ key prefix;
uses route;
}
- list linkstate-nodes {
- // FIXME: fill this out
-
- uses route;
- }
- list linkstate-ipv4-prefixes {
- // FIXME: fill this out
-
- uses route;
- }
- list linkstate-ipv6-prefixes {
- // FIXME: fill this out
+ }
+ case ipv6-routes {
+ list ipv6-routes {
+ when "../../afi = ipv6";
+
+ leaf prefix {
+ type inet:ipv6-prefix;
+ }
+ key prefix;
uses route;
}
package org.opendaylight.protocol.bgp.rib.impl;
import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
public final class Activator extends AbstractBindingAwareProvider {
+ @SuppressWarnings("unused")
private RIBImpl rib;
-
@Override
public void onSessionInitiated(final ProviderContext session) {
- rib = new RIBImpl(session.getSALService(DataProviderService.class));
+ this.rib = new RIBImpl(session.getSALService(DataProviderService.class));
}
}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
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.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateDestination;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
}
@Override
- public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
- final Ipv4Prefix key) {
+ public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv4Prefix key) {
final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv4Routes.class);
@Override
public void addRoutes(
- final DataModificationTransaction trans,
+ final DataModificationTransaction trans,
final Peer peer,
final MpReachNlri nlri,
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
}
};
- for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
+ for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
super.add(trans, peer, id, data);
}
}
@Override
- public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
- final MpUnreachNlri nlri) {
- for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
+ public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+ for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
super.remove(trans, peer, id);
}
}
}
@Override
- public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
- final Ipv6Prefix key) {
+ public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv6Prefix key) {
final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv6Routes.class);
@Override
public void addRoutes(
- final DataModificationTransaction trans,
+ final DataModificationTransaction trans,
final Peer peer,
final MpReachNlri nlri,
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
}
};
- for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
+ for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
super.add(trans, peer, id, data);
}
}
@Override
- public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
- final MpUnreachNlri nlri) {
- for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
+ public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+ for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
super.remove(trans, peer, id);
}
}
}
@Override
- public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
- final CLinkstateDestination key) {
+ public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final CLinkstateDestination key) {
final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
switch (key.getNlriType()) {
@Override
public void addRoutes(
- final DataModificationTransaction trans,
+ final DataModificationTransaction trans,
final Peer peer,
final MpReachNlri nlri,
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
- final CLinkstateDestination key =
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
- update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+ final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
RIBEntryData data = null;
switch (key.getNlriType()) {
}
@Override
- public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
- final MpUnreachNlri nlri) {
- final CLinkstateDestination key =
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
- update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstate) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
+ public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+ final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
super.remove(trans, peer, key);
}
static {
final AdjRIBsInFactoryRegistry reg = new AdjRIBsInFactoryRegistryImpl();
- reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new AdjRIBsInFactory() {
+ reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
@Override
public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
return new Ipv4AdjRIBsIn(comparator, key);
}
});
- reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new AdjRIBsInFactory() {
+ reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
@Override
public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
return new Ipv6AdjRIBsIn(comparator, key);
}
});
- reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
- new AdjRIBsInFactory() {
+ reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new AdjRIBsInFactory() {
@Override
public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
return new LinkstateAdjRIBsIn(comparator, key);
final Class<? extends SubsequentAddressFamily> safi, final AdjRIBsInFactory factory) {
final TablesKey key = new TablesKey(afi, safi);
- if (factories.containsKey(key)) {
+ if (this.factories.containsKey(key)) {
throw new RuntimeException("Specified AFI/SAFI combination is already registered");
}
- factories.put(key, factory);
+ this.factories.put(key, factory);
final Object lock = this;
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
synchronized (lock) {
- factories.remove(key);
+ AdjRIBsInFactoryRegistryImpl.this.factories.remove(key);
}
}
};
}
@Override
- public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
- return factories.get(new TablesKey(afi, safi));
+ public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi) {
+ return this.factories.get(new TablesKey(afi, safi));
}
}
*/
public final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
- private static final int MAX_FRAME_SIZE = 4096; // min 19, max 4096
+ private static final int MAX_FRAME_SIZE = 4096;
private static final int MARKER_SIZE = 16;
- private static final int LENGTH_SIZE = 2; // the length field represents the length of the whole message including
- // the header
+ /*
+ * the length field represents the length of the whole message including the header
+ */
+ private static final int LENGTH_SIZE = 2;
/*
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
- + +
| |
- + +
+ | |
+ | |
| Marker |
- + +
+ | |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Type |
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
-
/**
* This comparator is intended to implement BGP Best Path Selection algorithm, as described at
*
@Override
public int compare(final PathAttributes o1, final PathAttributes o2) {
- if (o1 == o2) {
- return 0;
- }
if (o1 == null) {
return 1;
}
if (o2 == null) {
return -1;
}
+ if (o1.equals(o2)) {
+ return 0;
+ }
// FIXME: look at ASPath
// FIXME: look at everything else :-)
@Override
public void onMessage(final BGPSession session, final Notification message) {
if (message instanceof Update) {
- this.rib.updateTables(this, (Update)message);
+ this.rib.updateTables(this, (Update) message);
} else {
logger.info("Ignoring unhandled message class " + message.getClass());
}
public void onSessionUp(final BGPSession session) {
logger.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
- for (BgpTableType t : session.getAdvertisedTableTypes()) {
- tables.add(new TablesKey(t.getAfi(), t.getSafi()));
+ for (final BgpTableType t : session.getAdvertisedTableTypes()) {
+ this.tables.add(new TablesKey(t.getAfi(), t.getSafi()));
}
}
this.rib.clearTable(this, key);
}
- tables.clear();
+ this.tables.clear();
}
@Override
}
@Override
- public final String toString() {
+ public String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
+ /*
+ * 240
+ */
private static final int DEFAULT_HOLD_TIMER_VALUE = 15;
private static final Notification keepalive = new KeepaliveBuilder().build();
- public static int HOLD_TIMER_VALUE = DEFAULT_HOLD_TIMER_VALUE; // 240
+ private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE;
/**
* Internal session state.
/**
* System.nanoTime value about when was sent the last message Protected to be updated also in tests.
*/
+ @VisibleForTesting
protected long lastMessageSentAt;
/**
this.stateTimer = Preconditions.checkNotNull(timer);
this.channel = Preconditions.checkNotNull(channel);
this.keepAlive = remoteOpen.getHoldTimer() / 3;
+ holdTimerValue = remoteOpen.getHoldTimer();
- final Set<BgpTableType> tts = Sets.newHashSet();
+ final Set<TablesKey> tts = Sets.newHashSet();
+ final Set<BgpTableType> tats = Sets.newHashSet();
if (remoteOpen.getBgpParameters() != null) {
for (final BgpParameters param : remoteOpen.getBgpParameters()) {
if (param instanceof CParameters) {
final CParameters cp = (CParameters) param;
- final BgpTableType tt = new BgpTableTypeImpl(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
+ final TablesKey tt = new TablesKey(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
tts.add(tt);
+ tats.add(new BgpTableTypeImpl(tt.getAfi(), tt.getSafi()));
}
}
}
this.sync = new BGPSynchronization(this, this.listener, tts);
- this.tableTypes = tts;
+ this.tableTypes = tats;
if (remoteOpen.getHoldTimer() != 0) {
this.stateTimer.newTimeout(new TimerTask() {
}
final long ct = System.nanoTime();
- final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(HOLD_TIMER_VALUE);
+ final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(holdTimerValue);
if (ct >= nextHold) {
logger.debug("HoldTimer expired. " + new Date());
}
@Override
- final public String toString() {
+ public final String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
switch (this.state) {
case Finished:
case Idle:
- final Notify fsm_error = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
+ final Notify fsmError = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
BGPError.FSM_ERROR.getSubcode()).build();
- this.channel.writeAndFlush(fsm_error);
+ this.channel.writeAndFlush(fsmError);
case OpenConfirm:
if (msg instanceof Keepalive) {
negotiationSuccessful(this.session);
case OpenSent:
if (msg instanceof Open) {
final Open openObj = (Open) msg;
-
- final List<BgpParameters> prefs = openObj.getBgpParameters();
- if (prefs != null && !prefs.isEmpty()) {
- for (final BgpParameters param : openObj.getBgpParameters()) {
- final CParameters cap = param.getCParameters();
- if (cap instanceof CMultiprotocol) {
- if (((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
- && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
- this.remotePref = openObj;
- this.channel.writeAndFlush(new KeepaliveBuilder().build());
- this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
- this.state = State.OpenConfirm;
- logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
- return;
- }
- }
- }
- }
- final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
- BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
- this.channel.writeAndFlush(ntf);
- negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
- ntf.getErrorCode(), ntf.getErrorSubcode())));
- this.state = State.Finished;
+ handleOpen(openObj);
return;
}
break;
this.state = State.Finished;
}
+ private void handleOpen(final Open openObj) {
+ final List<BgpParameters> prefs = openObj.getBgpParameters();
+ if (prefs != null && !prefs.isEmpty()) {
+ for (final BgpParameters param : openObj.getBgpParameters()) {
+ final CParameters cap = param.getCParameters();
+ if (cap instanceof CMultiprotocol
+ && ((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
+ && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
+ this.remotePref = openObj;
+ this.channel.writeAndFlush(new KeepaliveBuilder().build());
+ this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
+ this.state = State.OpenConfirm;
+ logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
+ return;
+ }
+ }
+ }
+ final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
+ BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
+ this.channel.writeAndFlush(ntf);
+ negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
+ ntf.getErrorCode(), ntf.getErrorSubcode())));
+ this.state = State.Finished;
+ }
+
public synchronized State getState() {
return this.state;
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
this.bgpId = bgpId;
final List<BgpParameters> tlvs = Lists.newArrayList();
- tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
- Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()));
- tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
- LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).build()));
- // final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
- // tableTypes.put(ipv4, true);
- // tableTypes.put(linkstate,true);
- // tlvs.add(new GracefulCapability(true, 0, tableTypes));
- tlvs.add((BgpParameters) new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(
- new AsNumber((long) as)).build()));
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CMultiprotocolBuilder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build());
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CMultiprotocolBuilder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(LinkstateAddressFamily.class).setSafi(
+ LinkstateSubsequentAddressFamily.class).build()).build()).build());
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) as)).build()).build()).build());
this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
}
}
- private final Map<BgpTableType, SyncVariables> syncStorage = Maps.newHashMap();
+ private final Map<TablesKey, SyncVariables> syncStorage = Maps.newHashMap();
private final BGPSessionListener listener;
private final BGPSession session;
- public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<BgpTableType> types) {
+ public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<TablesKey> types) {
this.listener = Preconditions.checkNotNull(listener);
this.session = Preconditions.checkNotNull(bgpSession);
- for (final BgpTableType type : types) {
+ for (final TablesKey type : types) {
this.syncStorage.put(type, new SyncVariables());
}
}
if (msg.getNlri() != null || msg.getWithdrawnRoutes() != null) {
type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
} else if (msg.getPathAttributes().getAugmentation(PathAttributes1.class) != null) {
- PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
+ final PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
if (pa.getMpReachNlri() != null) {
type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
}
} else if (msg.getPathAttributes().getAugmentation(PathAttributes2.class) != null) {
- PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
+ final PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
if (pa.getMpUnreachNlri() != null) {
type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
}
* session.
*/
public void kaReceived() {
- for (final Entry<BgpTableType, SyncVariables> entry : this.syncStorage.entrySet()) {
+ for (final Entry<TablesKey, SyncVariables> entry : this.syncStorage.entrySet()) {
final SyncVariables s = entry.getValue();
if (!s.getEor()) {
if (!s.getUpd()) {
}
}
- private Update generateEOR(final BgpTableType type) {
+ private Update generateEOR(final TablesKey type) {
if (type.getAfi().equals(Ipv4AddressFamily.class) && type.getSafi().equals(UnicastSubsequentAddressFamily.class)) {
return new UpdateBuilder().build();
}
- return new UpdateBuilder().setPathAttributes(new PathAttributesBuilder().addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
+ return new UpdateBuilder().setPathAttributes(
+ new PathAttributesBuilder().addAugmentation(
+ PathAttributes1.class,
+ new PathAttributes1Builder().setMpReachNlri(
+ new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
}
}
import javax.annotation.concurrent.ThreadSafe;
-
-
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
}
synchronized void updateTables(final BGPPeer peer, final Update message) {
- final DataModificationTransaction trans = dps.beginTransaction();
+ final DataModificationTransaction trans = this.dps.beginTransaction();
// FIXME: detect and handle end-of-RIB markers
- //remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- // trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
+ // remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+ // trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
final PathAttributes attrs = message.getPathAttributes();
final PathAttributes2 mpu = attrs.getAugmentation(PathAttributes2.class);
if (mpu != null) {
final MpUnreachNlri nlri = mpu.getMpUnreachNlri();
- AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+ final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
if (ari != null) {
ari.removeRoutes(trans, peer, nlri);
} else {
}
}
- //add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- // trans, peer, message.getNlri().getNlri().iterator(), attrs);
+ // add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+ // trans, peer, message.getNlri().getNlri().iterator(), attrs);
final PathAttributes1 mpr = message.getPathAttributes().getAugmentation(PathAttributes1.class);
if (mpr != null) {
final MpReachNlri nlri = mpr.getMpReachNlri();
- final AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+ final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
if (ari != null) {
ari.addRoutes(trans, peer, nlri, attrs);
} else {
}
// FIXME: we need to attach to this future for failures
- Future<RpcResult<TransactionStatus>> f = trans.commit();
+ final Future<RpcResult<TransactionStatus>> f = trans.commit();
}
synchronized void clearTable(final BGPPeer peer, final TablesKey key) {
- final AdjRIBsIn ari = tables.get(key);
+ final AdjRIBsIn ari = this.tables.get(key);
if (ari != null) {
- final DataModificationTransaction trans = dps.beginTransaction();
+ final DataModificationTransaction trans = this.dps.beginTransaction();
ari.clear(trans, peer);
// FIXME: we need to attach to this future for failures
- Future<RpcResult<TransactionStatus>> f = trans.commit();
+ final Future<RpcResult<TransactionStatus>> f = trans.commit();
}
}
@Override
- public final String toString() {
+ public String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
import io.netty.util.concurrent.Future;
-import java.io.IOException;
import java.net.InetSocketAddress;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
* @param connection attributes required for connection
* @param parser BGP message parser
* @return client session
- * @throws IOException
*/
- Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener, final ReconnectStrategy strategy);
+ Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener,
+ final ReconnectStrategy strategy);
}
package org.opendaylight.protocol.bgp.rib.impl;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import java.util.Collections;
import java.util.Set;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+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.linkstate.rev130918.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
public class SynchronizationTest {
@Before
public void setUp() {
this.listener = new SimpleSessionListener();
-// final BGPIPv4RouteImpl i4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("1.1.1.1/32"), new BaseBGPObjectState(null, null), null);
-// this.ipv4m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i4), Collections.EMPTY_SET);
-// final BGPIPv6RouteImpl i6 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("::1/32"), new BaseBGPObjectState(null, null), null);
-// this.ipv6m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i6), Collections.EMPTY_SET);
-// this.lsm = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(mock(BGPLink.class)), Collections.EMPTY_SET);
+ this.ipv4m = new UpdateBuilder().setNlri(new NlriBuilder().setNlri(Lists.newArrayList(new Ipv4Prefix("1.1.1.1/32"))).build()).build();
- final Set<BgpTableType> types = Sets.newHashSet();
- types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAfi(Ipv6AddressFamily.class);
+ mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+
+ PathAttributesBuilder paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes1.class,
+ new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
+
+ this.ipv6m = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+ final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
+ mpUBuilder.setAfi(LinkstateAddressFamily.class);
+ mpUBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+
+ paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes2.class,
+ new PathAttributes2Builder().setMpUnreachNlri(mpUBuilder.build()).build());
+
+ this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+ final Set<TablesKey> types = Sets.newHashSet();
+ types.add(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+ types.add(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
this.bs = new BGPSynchronization(new BGPSession() {
@Override
public Set<BgpTableType> getAdvertisedTableTypes() {
+ final Set<BgpTableType> types = Sets.newHashSet();
+ types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+ types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
return types;
}
}, this.listener, types);
}
@Test
- @Ignore
- //FIXME: to be fixed in testing phase
public void testSynchronize() {
// simulate sync
-// this.bs.updReceived(this.ipv6m);
-//
-// this.bs.updReceived(this.ipv4m);
-// this.bs.updReceived(this.lsm);
-// this.bs.kaReceived(); // nothing yet
-// this.bs.updReceived(this.ipv4m);
+ this.bs.updReceived(this.ipv6m);
+ this.bs.updReceived(this.ipv4m);
+ this.bs.updReceived(this.lsm);
+ this.bs.kaReceived(); // nothing yet
+ this.bs.updReceived(this.ipv4m);
this.bs.kaReceived(); // linkstate
assertEquals(1, this.listener.getListMsg().size());
+ assertEquals(
+ LinkstateAddressFamily.class,
+ ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
this.bs.kaReceived(); // ipv4 sync
assertEquals(2, this.listener.getListMsg().size());
- assertEquals(Ipv4AddressFamily.class,
- ((Update) this.listener.getListMsg().get(1)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
}
}
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.NotifyBuilder;
import org.opendaylight.yangtools.yang.binding.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
*/
@ThreadSafe
public final class BGPMock implements BGP, Closeable {
- static final Notification connectionLostMagicMessage = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
+
+ private static final Logger logger = LoggerFactory.getLogger(BGPMock.class);
+
+ static final Notification CONNECTION_LOST_MAGIC_MSG = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
@GuardedBy("this")
private final List<byte[]> allPreviousByteMessages;
messages.add(parser.parse(body));
}
} catch (final DeserializerException e) {
- e.printStackTrace();
+ logger.warn(e.getMessage(), e);
} catch (final DocumentedException e) {
- e.printStackTrace();
+ logger.warn(e.getMessage(), e);
}
return messages;
}
}
public synchronized void insertConnectionLostEvent() {
- this.insertMessage(connectionLostMagicMessage);
+ this.insertMessage(CONNECTION_LOST_MAGIC_MSG);
}
public synchronized void insertMessages(final List<Notification> messages) {
* This class has @Subscribe annotated methods which receive events from {@link EventBus} . Events are produced by
* {@link BGPMock}, and each instance notifies exactly one {@link BGPSessionListener}.
*/
-class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
+final class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
private final EventBus eventBus;
public static EventBusRegistration createAndRegister(final EventBus eventBus, final BGPSessionListener listener,
}
private static void sendMessage(final BGPSessionListener listener, final Notification message) {
- if (BGPMock.connectionLostMagicMessage.equals(message)) {
+ if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
listener.onSessionTerminated(null, null);
} else if (message instanceof Open) {
final Set<BgpTableType> tts = Sets.newHashSet();
return tts;
}
});
- } else if (message instanceof Keepalive) {
- // do nothing
- } else {
+ } else if (!(message instanceof Keepalive)) {
listener.onMessage(null, message);
}
}
@ThreadSafe
public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements AdjRIBsIn {
protected abstract class RIBEntryData {
- final PathAttributes attributes;
+ private final PathAttributes attributes;
protected RIBEntryData(final PathAttributes attributes) {
this.attributes = Preconditions.checkNotNull(attributes);
}
+ public PathAttributes getPathAttributes() {
+ return this.attributes;
+ }
+
protected abstract DATA getDataObject(ID key);
}
/**
- * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based on
- * ordering specified by the supplied comparator.
- *
+ * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based
+ * on ordering specified by the supplied comparator.
+ *
*/
private final class RIBEntry {
/*
}
private InstanceIdentifier<?> getName() {
- if (name == null) {
- name = identifierForKey(basePath, key);
+ if (this.name == null) {
+ this.name = identifierForKey(AbstractAdjRIBsIn.this.basePath, this.key);
}
- return name;
+ return this.name;
}
private RIBEntryData findCandidate(final RIBEntryData initial) {
RIBEntryData newState = initial;
for (final RIBEntryData s : this.candidates.values()) {
- if (newState == null || comparator.compare(newState.attributes, s.attributes) > 0) {
+ if (newState == null || AbstractAdjRIBsIn.this.comparator.compare(newState.attributes, s.attributes) > 0) {
newState = s;
}
}
private void electCandidate(final DataModificationTransaction transaction, final RIBEntryData candidate) {
if (this.currentState == null || !this.currentState.equals(candidate)) {
- transaction.putRuntimeData(getName(), candidate.getDataObject(key));
+ transaction.putRuntimeData(getName(), candidate.getDataObject(this.key));
this.currentState = candidate;
}
}
electCandidate(transaction, candidate);
return true;
} else {
- transaction.removeRuntimeData(name);
+ transaction.removeRuntimeData(this.name);
return false;
}
}
- synchronized void setState(final DataModificationTransaction transaction, final Peer peer, final RIBEntryData state) {
+ synchronized void setState(final DataModificationTransaction transaction, final Peer peer, final RIBEntryData state) {
this.candidates.put(peer, state);
electCandidate(transaction, findCandidate(state));
}
protected AbstractAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
this.comparator = Preconditions.checkNotNull(comparator);
- basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
+ this.basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
}
@Override
protected abstract InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final ID id);
- protected synchronized void add(final DataModificationTransaction trans, final Peer peer, final ID id, final RIBEntryData data) {
+ protected synchronized void add(final DataModificationTransaction trans, final Peer peer, final ID id, final RIBEntryData data) {
RIBEntry e = this.entries.get(id);
if (e == null) {
e = new RIBEntry(id);
e.setState(trans, peer, data);
}
- protected synchronized void remove(final DataModificationTransaction trans, final Peer peer, final ID id) {
+ protected synchronized void remove(final DataModificationTransaction trans, final Peer peer, final ID id) {
final RIBEntry e = this.entries.get(id);
if (e != null && e.removeState(trans, peer)) {
this.entries.remove(id);
import io.netty.util.concurrent.GlobalEventExecutor;
-import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
*/
public class Main {
- private final static Logger logger = LoggerFactory.getLogger(Main.class);
+ private static final Logger logger = LoggerFactory.getLogger(Main.class);
- public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
- + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+ private static String usage = "DESCRIPTION:\n"
+ + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
+ + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+ "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
+ "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
"With no parameters, this help is printed.";
- BGPDispatcherImpl dispatcher;
+ private final BGPDispatcherImpl dispatcher;
- public Main() throws IOException {
- this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry()));
+ private static final int INITIAL_HOLD_TIME = 90;
+
+ private static final int RECONNECT_MILLIS = 5000;
+
+ Main() throws Exception {
+ this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
}
- public static void main(final String[] args) throws NumberFormatException, IOException {
+ public static void main(final String[] args) throws Exception {
if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
System.out.println(Main.usage);
return;
}
InetSocketAddress address = null;
- short holdTimerValue = 90;
+ short holdTimerValue = INITIAL_HOLD_TIME;
AsNumber as = null;
int i = 0;
as = new AsNumber(Long.valueOf(args[i + 1]));
i++;
} else {
- System.out.println("WARNING: Unrecognized argument: " + args[i]);
+ logger.error("WARNING: Unrecognized argument: " + args[i]);
}
i++;
}
logger.debug("{} {} {}", address, sessionListener, proposal);
final InetSocketAddress addr = address;
- m.dispatcher.createClient(addr, proposal, sessionListener, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
+ m.dispatcher.createClient(addr, proposal, sessionListener,
+ new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS));
}
}
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
-import java.io.IOException;
import java.net.InetSocketAddress;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionNegotiatorFactory;
});
}
- public static void main(final String[] args) throws IOException {
+ public static void main(final String[] args) throws Exception {
final SessionListenerFactory<BGPSessionListener> f = new SessionListenerFactory<BGPSessionListener>() {
@Override
final SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs);
final BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<>(snf,
- new BGPHandlerFactory(new BGPMessageFactoryImpl(BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry())),
+ new BGPHandlerFactory(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry())),
new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
mock.createServer(new InetSocketAddress("127.0.0.2", 12345), f);
*/
package org.opendaylight.protocol.bgp.util;
-import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@Immutable
public final class BinaryBGPDumpFileParser {
- private static final byte ff = (byte) 255;
- private static final Logger LOG = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
+ private static final Logger logger = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
private static final int MINIMAL_LENGTH = 19;
+ private static final int MARKER_LENGTH = 16;
+
+ private BinaryBGPDumpFileParser() {
+
+ }
+
/**
* Extract BGP messages from binary file in MRT format.
*
* @param file file with BGP messages in binary form.
* @return list with byte arrays representing extracted messages.
- * @throws IOException
*/
public static List<byte[]> parseMessages(final byte[] byteArray) {
final byte b = byteArray[i];
// Marker start
- if (b == ff) {
+ if (b == UnsignedBytes.MAX_VALUE) {
final int start = i;
int ffCount = 0;
for (int j = i; j < i + (17); j++) {
// Check marker
- if (byteArray[j] == ff) {
+ if (byteArray[j] == UnsignedBytes.MAX_VALUE) {
ffCount++;
- } else if (ffCount == 16) {
- if (j == (i + 16)) {
+ } else if (ffCount == MARKER_LENGTH) {
+ if (j == (i + MARKER_LENGTH)) {
// Parse length
final int length = UnsignedBytes.toInt(byteArray[j]) * 256 + UnsignedBytes.toInt(byteArray[j + 1]);
final byte[] message = Arrays.copyOfRange(byteArray, start, start + length);
messages.add(message);
- j += length - 16;
+ j += length - MARKER_LENGTH;
}
i = j;
break;
}
}
- LOG.info("Succesfully extracted " + messages.size() + " messages");
+ logger.info("Succesfully extracted {} messages", messages.size());
return messages;
}
}
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import com.google.common.io.CharStreams;
/**
- * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff marker.
- * New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to this format.
+ * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff
+ * marker. New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to
+ * this format.
*/
@Immutable
-public class HexDumpBGPFileParser {
+public final class HexDumpBGPFileParser {
private static final int MINIMAL_LENGTH = 19;
- private static final Logger LOG = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
- private static final String ff_16 = Strings.repeat("FF", 16);
+ private static final Logger logger = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
+ private static final String FF_16 = Strings.repeat("FF", 16);
- public static List<byte[]> parseMessages(final File file) throws FileNotFoundException, IOException {
+ private HexDumpBGPFileParser() {
+
+ }
+
+ public static List<byte[]> parseMessages(final File file) throws IOException {
Preconditions.checkArgument(file != null, "Filename cannot be null");
return parseMessages(new FileInputStream(file));
}
}
}
- public static List<byte[]> parseMessages(String content) {
- content = clearWhiteSpace_toUpper(content);
+ public static List<byte[]> parseMessages(final String c) {
+ final String content = clearWhiteSpaceToUpper(c);
// search for 16 FFs
- List<byte[]> messages = Lists.newLinkedList();
+ final List<byte[]> messages = Lists.newLinkedList();
int idx = 0;
- while ((idx = content.indexOf(ff_16, idx)) > -1) {
+ while ((idx = content.indexOf(FF_16, idx)) > -1) {
// next 2 bytes are length
- int lengthIdx = idx + 16 * 2;
- int messageIdx = lengthIdx + 4;
- String hexLength = content.substring(lengthIdx, messageIdx);
+ final int lengthIdx = idx + 16 * 2;
+ final int messageIdx = lengthIdx + 4;
+ final String hexLength = content.substring(lengthIdx, messageIdx);
byte[] byteLength = null;
try {
byteLength = Hex.decodeHex(hexLength.toCharArray());
- } catch (DecoderException e) {
+ } catch (final DecoderException e) {
throw new RuntimeException(e);
}
- int length = ByteArray.bytesToInt(byteLength);
- int messageEndIdx = idx + length * 2;
+ final int length = ByteArray.bytesToInt(byteLength);
+ final int messageEndIdx = idx + length * 2;
// Assert that message is longer than minimum 19(header.length == 19)
// If length in BGP message would be 0, loop would never end
- Preconditions.checkArgument(length >= MINIMAL_LENGTH,
- "Invalid message at index " + idx
- + ", length atribute is lower than " + MINIMAL_LENGTH);
+ Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than "
+ + MINIMAL_LENGTH);
- String hexMessage = content.substring(idx, messageEndIdx);
+ final String hexMessage = content.substring(idx, messageEndIdx);
byte[] message = null;
try {
message = Hex.decodeHex(hexMessage.toCharArray());
- } catch (DecoderException e) {
+ } catch (final DecoderException e) {
new RuntimeException(e);
}
messages.add(message);
idx = messageEndIdx;
}
- LOG.info("Succesfully extracted " + messages.size() + " messages");
+ logger.info("Succesfully extracted {} messages", messages.size());
return messages;
}
@VisibleForTesting
- static String clearWhiteSpace_toUpper(final String line){
+ static String clearWhiteSpaceToUpper(final String line) {
return line.replaceAll("\\s", "").toUpperCase();
}
@Test
public void testCleanWhiteSpace() {
final String input = "abc def\r\nghi\nj";
- assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpace_toUpper(input));
+ assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpaceToUpper(input));
}
@Test
*/
package org.opendaylight.protocol.concepts;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
import javax.annotation.concurrent.ThreadSafe;
-import com.google.common.base.Preconditions;
-
@ThreadSafe
public class HandlerRegistry<CLASS, PARSER, SERIALIZER> {
- private final Map<Class<? extends CLASS>, SERIALIZER> serializers = new ConcurrentHashMap<>();
- private final Map<Integer, PARSER> parsers = new ConcurrentHashMap<>();
+ private final MultiRegistry<Class<? extends CLASS>, SERIALIZER> serializers = new MultiRegistry<>();
+ private final MultiRegistry<Integer, PARSER> parsers = new MultiRegistry<>();
- public AutoCloseable registerParser(final int type, final PARSER parser) {
- synchronized (parsers) {
- Preconditions.checkArgument(!parsers.containsKey(type), "Type %s already registered", type);
- parsers.put(type, parser);
-
- return new AbstractRegistration() {
- @Override
- protected void removeRegistration() {
- synchronized (parsers) {
- parsers.remove(type);
- }
- }
- };
- }
+ public AbstractRegistration registerParser(final int type, final PARSER parser) {
+ return parsers.register(type, parser);
}
public PARSER getParser(final int type) {
return parsers.get(type);
}
- public AutoCloseable registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
- synchronized (serializers) {
- Preconditions.checkArgument(!serializers.containsKey(clazz), "Message class %s already registered", clazz);
- serializers.put(clazz, serializer);
-
- return new AbstractRegistration() {
- @Override
- protected void removeRegistration() {
- synchronized (serializers) {
- serializers.remove(clazz);
- }
- }
- };
- }
+ public AbstractRegistration registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
+ return serializers.register(clazz, serializer);
}
public SERIALIZER getSerializer(final Class<? extends CLASS> clazz) {
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
+import com.google.common.primitives.Bytes;
import com.google.common.primitives.UnsignedBytes;
/**
*/
public final class Ipv4Util {
+ public static final int IP4_LENGTH = 4;
+
public static Ipv4Address addressForBytes(final byte[] bytes) {
try {
- return new Ipv4Address(Inet4Address.getByAddress(bytes).getHostAddress());
+ return new Ipv4Address(InetAddresses.toAddrString(Inet4Address.getByAddress(bytes)));
} catch (final UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage());
}
return a.getAddress();
}
+ public static byte[] bytesForPrefix(final Ipv4Prefix prefix) {
+ final String p = prefix.getValue();
+ final int sep = p.indexOf("/");
+ try {
+ final byte[] bytes = Inet4Address.getByName(p.substring(0, sep)).getAddress();
+ return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length() - 1)) });
+ } catch (final UnknownHostException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+
public static Ipv4Prefix prefixForBytes(final byte[] bytes, final int length) {
Preconditions.checkArgument(length <= bytes.length * 8);
- return new Ipv4Prefix(addressForBytes(bytes).toString() + "/" + length);
+ final byte[] tmp = Arrays.copyOfRange(bytes, 0, 4);
+ InetAddress a = null;
+ try {
+ a = InetAddress.getByAddress(tmp);
+ } catch (final UnknownHostException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return new Ipv4Prefix(InetAddresses.toAddrString(a) + "/" + length);
}
public static List<Ipv4Prefix> prefixListForBytes(final byte[] bytes) {
- if (bytes.length == 0)
+ if (bytes.length == 0) {
return Collections.emptyList();
+ }
final List<Ipv4Prefix> list = Lists.newArrayList();
int byteOffset = 0;
p = prefix.getIpv6Prefix().getValue();
}
final int sep = p.indexOf("/");
- return Integer.valueOf(p.substring(sep, p.length() - 1));
+ return Integer.valueOf(p.substring(sep + 1, p.length()));
}
}
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
+import com.google.common.primitives.Bytes;
import com.google.common.primitives.UnsignedBytes;
/**
*/
public class Ipv6Util {
+ public static final int IPV6_LENGTH = 16;
+
public static Ipv6Address addressForBytes(final byte[] bytes) {
try {
- return new Ipv6Address(Inet6Address.getByAddress(bytes).toString());
+ return new Ipv6Address(InetAddresses.toAddrString(Inet6Address.getByAddress(bytes)));
} catch (final UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage());
}
return a.getAddress();
}
+ public static byte[] bytesForPrefix(final Ipv6Prefix prefix) {
+ final String p = prefix.getValue();
+ final int sep = p.indexOf("/");
+ try {
+ final byte[] bytes = Inet6Address.getByName(p.substring(0, sep)).getAddress();
+ return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length() - 1)) });
+ } catch (final UnknownHostException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+
public static Ipv6Prefix prefixForBytes(final byte[] bytes, final int length) {
Preconditions.checkArgument(length <= bytes.length * 8);
- return new Ipv6Prefix(addressForBytes(bytes).toString() + "/" + length);
+ final byte[] tmp = Arrays.copyOfRange(bytes, 0, 16);
+ InetAddress a = null;
+ try {
+ a = InetAddress.getByAddress(tmp);
+ } catch (final UnknownHostException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return new Ipv6Prefix(InetAddresses.toAddrString(a) + "/" + length);
}
public static List<Ipv6Prefix> prefixListForBytes(final byte[] bytes) {
- if (bytes.length == 0)
+ if (bytes.length == 0) {
return Collections.emptyList();
+ }
final List<Ipv6Prefix> list = Lists.newArrayList();
int byteOffset = 0;
--- /dev/null
+/*
+ * Copyright (c) 2013 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.concepts;
+
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.ThreadSafe;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+
+@ThreadSafe
+public final class MultiRegistry<K, V> {
+ private final ConcurrentMap<K, V> current = new ConcurrentHashMap<>();
+
+ @GuardedBy("this")
+ private final ListMultimap<K, V> candidates = ArrayListMultimap.create();
+
+ public synchronized AbstractRegistration register(final K key, final V value) {
+ // Put this value into candidates, then put it into the the current
+ // map, if it does not have a key -- this is to prevent unnecessary
+ // churn by replacing an already-present mapping.
+ candidates.put(key, value);
+ current.putIfAbsent(key, value);
+
+ final Object lock = this;
+ return new AbstractRegistration() {
+ @Override
+ protected void removeRegistration() {
+ synchronized (lock) {
+ // The delete sequencing is a bit more complex, as we want
+ // to prevent churn and we do not want the user to see
+ // the current map without a mapping as long as a candidate
+ // exists. To achieve this, we remove the entry from
+ // candidates and then check if the list of candidates for
+ // this key has become empty. If it has, we just remove
+ // the mapping. If there are candidates, then attempt to
+ // replace it -- but only if it has pointed to the removed
+ // value in the first place.
+ candidates.remove(key, value);
+
+ final List<V> values = candidates.get(key);
+ if (values.isEmpty()) {
+ current.remove(key);
+ } else {
+ current.replace(key, value, values.get(0));
+ }
+ }
+ }
+ };
+ }
+
+ public V get(final K key) {
+ return current.get(key);
+ }
+}
prefix "nps-c";
import ieee754 { prefix ieee754; revision-date 2013-08-19; }
- import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
organization "Cisco Systems, Inc.";
contact "Dana Kutenicsova <dkutenic@cisco.com>";
*/
package org.opendaylight.protocol.concepts;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.net.UnknownHostException;
+import java.util.List;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import com.google.common.collect.Lists;
+
public class IPAddressesAndPrefixesTest {
@Test
assertTrue("123.123.123.123/24".equals(new Ipv4Prefix("123.123.123.123/24").getValue()));
assertTrue("2001::1/120".equals(new Ipv6Prefix("2001::1/120").getValue()));
}
+
+ @Test
+ public void testPrefix4ForBytes() {
+ final byte[] bytes = new byte[] { 123, 122, 4, 5 };
+ assertEquals(new Ipv4Prefix("123.122.4.5/32"), Ipv4Util.prefixForBytes(bytes, 32));
+ }
+
+ @Test
+ public void testAddress4ForBytes() {
+ final byte[] bytes = new byte[] { (byte) 123, (byte) 122, (byte) 4, (byte) 5 };
+ assertEquals(new Ipv4Address("123.122.4.5"), Ipv4Util.addressForBytes(bytes));
+ try {
+ Ipv4Util.addressForBytes(new byte[] { 22, 44, 66, 18, 88, 33 });
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("addr is of illegal length", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testPrefixList4ForBytes() {
+ final byte[] bytes = new byte[] { 22, (byte) 172, (byte) 168, 3, 8, 12, 32, (byte) 192, (byte) 168, 35, 100 };
+ final List<Ipv4Prefix> prefs = Ipv4Util.prefixListForBytes(bytes);
+ assertEquals(
+ Lists.newArrayList(new Ipv4Prefix("172.168.3.0/22"), new Ipv4Prefix("12.0.0.0/8"), new Ipv4Prefix("192.168.35.100/32")),
+ prefs);
+ }
+
+ @Test
+ public void testPrefix6ForBytes() {
+ final byte[] bytes = new byte[] { 0x20, 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02 };
+ assertEquals(new Ipv6Prefix("2001:db8:1:2::/64"), Ipv6Util.prefixForBytes(bytes, 64));
+ }
+
+ @Test
+ public void testPrefixList6ForBytes() {
+ final List<Ipv6Prefix> prefs = Lists.newArrayList();
+ prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
+ prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
+ prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
+
+ }
+
+ @Test
+ public void testPrefixLength() {
+ assertEquals(22, Ipv4Util.getPrefixLength(new IpPrefix(new Ipv4Prefix("172.168.3.0/22"))));
+ assertEquals(64, Ipv4Util.getPrefixLength(new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/64"))));
+ }
}
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>programming-api</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>programming-tunnel-api</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-api</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-segment-routing</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-tunnel-api</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-tunnel-pcep</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-binding-broker-impl</artifactId>
public final class BgpLinkstateBundleTest extends AbstractBundleTest {
@Override
protected Collection<String> prerequisiteBundles() {
- return Lists.newArrayList("bgp-concepts", "bgp-parser-api", "bgp-parser-spi", "concepts", "framework", "rsvp-api", "util");
+ return Lists.newArrayList("bgp-concepts", "bgp-parser-api", "bgp-parser-spi", "bgp-rib-api", "concepts", "framework", "rsvp-api", "util");
}
@Override
*/
package org.opendaylight.protocol.pcep;
+import java.net.InetAddress;
+import java.util.concurrent.Future;
+
import org.opendaylight.protocol.framework.ProtocolSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
/**
* PCEP Session represents the finite state machine in PCEP, including timers and its purpose is to create a PCEP
* Sends message from user to PCE/PCC. If the user sends an Open Message, the session returns an error (open message
* is only allowed, when a PCEP handshake is in progress). Close message will close the session and free all the
* resources.
- *
+ *
* @param message message to be sent
+ * @return Future promise which will be succeed when the message is enqueued in the socket.
*/
- public void sendMessage(Message message);
+ Future<Void> sendMessage(Message message);
public void close(TerminationReason reason);
+
+ public Tlvs getRemoteTlvs();
+
+ public InetAddress getRemoteAddress();
}
}
}
+ typedef symbolic-path-name {
+ type binary;
+ }
+
+ typedef operational-status {
+ type enumeration {
+ enum down {
+ value 0;
+ }
+ enum up {
+ value 1;
+ }
+ enum active {
+ value 2;
+ }
+ enum going-down {
+ value 3;
+ }
+ enum going-up {
+ value 4;
+ }
+ }
+ }
+
// TLVs
grouping tlv {
description "Marker grouping for TLV groupings.";
}
}
- grouping p2mp-capable-tlv {
+ grouping p2mp-capable-tlv {
description "P2MP CAPABLE TLV";
reference "https://tools.ietf.org/html/rfc6006#section-3.1.2";
}
}
}
+ // FIXME: add tunnel endpoint (from stateful-07)
}
grouping symbolic-path-name-tlv {
uses tlv;
leaf path-name {
- type binary;
+ type symbolic-path-name;
mandatory true;
}
}
}
uses rsvp:explicit-route-subobjects {
-// FIXME: yangtools bug
-// augment "subobject-type" {
-// case path-key {
-// container path-key {
-// uses path-key-subobject;
-// }
-// }
-// }
+ augment "subobject-type" {
+ case path-key {
+ container path-key {
+ uses path-key-subobject;
+ }
+ }
+ }
}
}
}
uses object;
list subobjects {
- uses rsvp:record-route-subobjects;
+ uses rsvp:record-route-subobjects {
+ augment "subobject-type" {
+ case path-key {
+ container path-key {
+ uses path-key-subobject;
+ }
+ }
+ }
+ }
}
}
description "NOTIFICATION Object";
reference "https://tools.ietf.org/html/rfc5440#section-7.14";
- // No possibility of TLVs
uses object;
container "tlvs" {
container overload-duration {
description "PCEP-ERROR Object";
reference "https://tools.ietf.org/html/rfc5440#section-7.15";
- // No possibility of TLVs
uses object;
container "tlvs" {
container req-missing {
}
grouping lsp-object {
- description "SRP Object";
+ description "LSP Object";
reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3";
uses object;
uses rsvp-error-spec-tlv;
}
- container symblic-path-name {
+ container symbolic-path-name {
uses symbolic-path-name-tlv;
}
}
}
leaf operational {
- type enumeration {
- enum down {
- value 0;
- }
- enum up {
- value 1;
- }
- enum active {
- value 2;
- }
- enum going-down {
- value 3;
- }
- enum going-up {
- value 4;
- }
- }
+ type operational-status;
mandatory true;
}
<groupId>org.opendaylight.yangtools.model</groupId>
<artifactId>ietf-inet-types</artifactId>
<version>2010.09.24-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<configuration>
<instructions>
<Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
- <Export-Package>
+ <Private-Package>
org.opendaylight.protocol.pcep.impl.*,
- </Export-Package>
+ </Private-Package>
+ <Activator>org.opendaylight.protocol.pcep.parser.impl.BundleActivator</Activator>
</instructions>
</configuration>
</plugin>
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.protocol.pcep.impl.message.PCCreateMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPUpdateRequestMessageParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLspObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PredundancyGroupTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LoadBalancingObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspErrorCodeTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MetricObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfListTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OrderTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OverloadDurationTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeyObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcepErrorObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcinitiateMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcntfMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrepMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcreqMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrptMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcupdMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PredundancyGroupIdTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReqMissingTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RpObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SvecObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.IpPrefixSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1Label;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class Activator implements PCEPExtensionProviderActivator {
+ private static final Logger logger = LoggerFactory.getLogger(Activator.class);
+ private List<AutoCloseable> registrations;
+
+ @Override
+ public void start(final PCEPExtensionProviderContext context) {
+ Preconditions.checkState(this.registrations == null);
+ final List<AutoCloseable> regs = new ArrayList<>();
+
+ final LabelHandlerRegistry labelReg = context.getLabelHandlerRegistry();
+ context.registerLabelParser(Type1LabelParser.CTYPE, new Type1LabelParser());
+ context.registerLabelParser(GeneralizedLabelParser.CTYPE, new GeneralizedLabelParser());
+ context.registerLabelParser(WavebandSwitchingLabelParser.CTYPE, new WavebandSwitchingLabelParser());
+
+ context.registerLabelSerializer(Type1Label.class, new Type1LabelParser());
+ context.registerLabelSerializer(GeneralizedLabel.class, new GeneralizedLabelParser());
+ context.registerLabelSerializer(WavebandSwitchingLabel.class, new WavebandSwitchingLabelParser());
+
+ final EROSubobjectHandlerRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
+ context.registerEROSubobjectParser(EROIpPrefixSubobjectParser.TYPE, new EROIpPrefixSubobjectParser());
+ context.registerEROSubobjectParser(EROIpPrefixSubobjectParser.TYPE6, new EROIpPrefixSubobjectParser());
+ context.registerEROSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser());
+ context.registerEROSubobjectParser(EROLabelSubobjectParser.TYPE, new EROLabelSubobjectParser(labelReg));
+ context.registerEROSubobjectParser(EROUnnumberedInterfaceSubobjectParser.TYPE, new EROUnnumberedInterfaceSubobjectParser());
+ context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE, new EROPathKeySubobjectParser());
+ context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE128, new EROPathKeySubobjectParser());
+
+ context.registerEROSubobjectSerializer(IpPrefixSubobject.class, new EROIpPrefixSubobjectParser());
+ context.registerEROSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser());
+ context.registerEROSubobjectSerializer(LabelSubobject.class, new EROLabelSubobjectParser(labelReg));
+ context.registerEROSubobjectSerializer(UnnumberedSubobject.class, new EROUnnumberedInterfaceSubobjectParser());
+ context.registerEROSubobjectSerializer(PathKeySubobject.class, new EROPathKeySubobjectParser());
+
+ final RROSubobjectHandlerRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
+ context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE, new RROIpPrefixSubobjectParser());
+ context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE6, new RROIpPrefixSubobjectParser());
+ context.registerRROSubobjectParser(RROLabelSubobjectParser.TYPE, new RROLabelSubobjectParser(labelReg));
+ context.registerRROSubobjectParser(RROUnnumberedInterfaceSubobjectParser.TYPE, new RROUnnumberedInterfaceSubobjectParser());
+ context.registerRROSubobjectParser(RROPathKeySubobjectParser.TYPE, new RROPathKeySubobjectParser());
+ context.registerRROSubobjectParser(RROPathKeySubobjectParser.TYPE128, new RROPathKeySubobjectParser());
+
+ context.registerRROSubobjectSerializer(IpPrefixSubobject.class, new RROIpPrefixSubobjectParser());
+ context.registerRROSubobjectSerializer(LabelSubobject.class, new RROLabelSubobjectParser(labelReg));
+ context.registerRROSubobjectSerializer(UnnumberedSubobject.class, new RROUnnumberedInterfaceSubobjectParser());
+ context.registerRROSubobjectSerializer(PathKeySubobject.class, new RROPathKeySubobjectParser());
+
+ final XROSubobjectHandlerRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
+ context.registerXROSubobjectParser(XROIpPrefixSubobjectParser.TYPE, new XROIpPrefixSubobjectParser());
+ context.registerXROSubobjectParser(XROIpPrefixSubobjectParser.TYPE6, new XROIpPrefixSubobjectParser());
+ context.registerXROSubobjectParser(XROAsNumberSubobjectParser.TYPE, new XROAsNumberSubobjectParser());
+ context.registerXROSubobjectParser(XROSRLGSubobjectParser.TYPE, new XROSRLGSubobjectParser());
+ context.registerXROSubobjectParser(XROUnnumberedInterfaceSubobjectParser.TYPE, new XROUnnumberedInterfaceSubobjectParser());
+ context.registerXROSubobjectParser(XROPathKeySubobjectParser.TYPE, new XROPathKeySubobjectParser());
+ context.registerXROSubobjectParser(XROPathKeySubobjectParser.TYPE128, new XROPathKeySubobjectParser());
+
+ context.registerXROSubobjectSerializer(IpPrefixSubobject.class, new XROIpPrefixSubobjectParser());
+ context.registerXROSubobjectSerializer(AsNumberSubobject.class, new XROAsNumberSubobjectParser());
+ context.registerXROSubobjectSerializer(SrlgSubobject.class, new XROSRLGSubobjectParser());
+ context.registerXROSubobjectSerializer(UnnumberedSubobject.class, new XROUnnumberedInterfaceSubobjectParser());
+ context.registerXROSubobjectSerializer(PathKeySubobject.class, new XROPathKeySubobjectParser());
+
+ final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry();
+ context.registerTlvParser(NoPathVectorTlvParser.TYPE, new NoPathVectorTlvParser());
+ context.registerTlvParser(OverloadedDurationTlvParser.TYPE, new OverloadedDurationTlvParser());
+ context.registerTlvParser(ReqMissingTlvParser.TYPE, new ReqMissingTlvParser());
+ context.registerTlvParser(OFListTlvParser.TYPE, new OFListTlvParser());
+ context.registerTlvParser(OrderTlvParser.TYPE, new OrderTlvParser());
+ context.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser());
+ context.registerTlvParser(LspSymbolicNameTlvParser.TYPE, new LspSymbolicNameTlvParser());
+ context.registerTlvParser(LSPIdentifierTlvParser.TYPE, new LSPIdentifierTlvParser());
+ context.registerTlvParser(LSPIdentifierTlvParser.TYPE_6, new LSPIdentifierTlvParser());
+ context.registerTlvParser(LspUpdateErrorTlvParser.TYPE, new LspUpdateErrorTlvParser());
+ context.registerTlvParser(RSVPErrorSpecTlvParser.TYPE, new RSVPErrorSpecTlvParser());
+ context.registerTlvParser(LspDbVersionTlvParser.TYPE, new LspDbVersionTlvParser());
+ context.registerTlvParser(PredundancyGroupTlvParser.TYPE, new PredundancyGroupTlvParser());
+
+ context.registerTlvSerializer(NoPathVectorTlv.class, new NoPathVectorTlvParser());
+ context.registerTlvSerializer(OverloadDurationTlv.class, new OverloadedDurationTlvParser());
+ context.registerTlvSerializer(ReqMissingTlv.class, new ReqMissingTlvParser());
+ context.registerTlvSerializer(OfListTlv.class, new OFListTlvParser());
+ context.registerTlvSerializer(OrderTlv.class, new OrderTlvParser());
+ context.registerTlvSerializer(StatefulCapabilityTlv.class, new PCEStatefulCapabilityTlvParser());
+ context.registerTlvSerializer(SymbolicPathNameTlv.class, new LspSymbolicNameTlvParser());
+ context.registerTlvSerializer(LspIdentifiersTlv.class, new LSPIdentifierTlvParser());
+ context.registerTlvSerializer(LspErrorCodeTlv.class, new LspUpdateErrorTlvParser());
+ context.registerTlvSerializer(RsvpErrorSpecTlv.class, new RSVPErrorSpecTlvParser());
+ context.registerTlvSerializer(LspDbVersionTlv.class, new LspDbVersionTlvParser());
+ context.registerTlvSerializer(PredundancyGroupIdTlv.class, new PredundancyGroupTlvParser());
+
+ final ObjectHandlerRegistry objReg = context.getObjectHandlerRegistry();
+ context.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(tlvReg));
+ context.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE,
+ new PCEPRequestParameterObjectParser(tlvReg));
+ context.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(tlvReg));
+ context.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(tlvReg));
+ context.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6,
+ new PCEPEndPointsObjectParser(tlvReg));
+ context.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(tlvReg));
+ context.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE,
+ new PCEPBandwidthObjectParser(tlvReg));
+ context.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(tlvReg));
+
+ context.registerObjectParser(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE,
+ new PCEPExplicitRouteObjectParser(eroSubReg));
+ context.registerObjectParser(PCEPReportedRouteObjectParser.CLASS, PCEPReportedRouteObjectParser.TYPE,
+ new PCEPReportedRouteObjectParser(rroSubReg));
+ context.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser(tlvReg));
+ context.registerObjectParser(PCEPIncludeRouteObjectParser.CLASS, PCEPIncludeRouteObjectParser.TYPE,
+ new PCEPIncludeRouteObjectParser(eroSubReg));
+ context.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(tlvReg));
+ context.registerObjectParser(PCEPNotificationObjectParser.CLASS, PCEPNotificationObjectParser.TYPE,
+ new PCEPNotificationObjectParser(tlvReg));
+ context.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(tlvReg));
+ context.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE,
+ new PCEPLoadBalancingObjectParser(tlvReg));
+ context.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(tlvReg));
+ context.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(tlvReg));
+ context.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE,
+ new PCEPObjectiveFunctionObjectParser(tlvReg));
+ context.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(tlvReg));
+
+ context.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE,
+ new PCEPGlobalConstraintsObjectParser(tlvReg));
+ context.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(tlvReg));
+ context.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(tlvReg));
+ context.registerObjectParser(PCEPExcludeRouteObjectParser.CLASS, PCEPExcludeRouteObjectParser.TYPE,
+ new PCEPExcludeRouteObjectParser(xroSubReg));
+
+ context.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(tlvReg));
+ context.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(tlvReg));
+ context.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(tlvReg));
+ context.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(tlvReg));
+ context.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(tlvReg));
+ context.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(tlvReg));
+ context.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(eroSubReg));
+ context.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(rroSubReg));
+ context.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(tlvReg));
+ context.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(eroSubReg));
+ context.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(tlvReg));
+ context.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(tlvReg));
+ context.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg));
+ context.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg));
+ context.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg));
+ context.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(tlvReg));
+ context.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg));
+ context.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg));
+ context.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(tlvReg));
+ context.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(tlvReg));
+ context.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(tlvReg));
+ context.registerObjectSerializer(ExcludeRouteObject.class, new PCEPExcludeRouteObjectParser(xroSubReg));
+
+ context.registerMessageParser(PCEPOpenMessageParser.TYPE, new PCEPOpenMessageParser(objReg));
+ context.registerMessageParser(PCEPKeepAliveMessageParser.TYPE, new PCEPKeepAliveMessageParser(objReg));
+ context.registerMessageParser(PCEPReplyMessageParser.TYPE, new PCEPReplyMessageParser(objReg));
+ context.registerMessageParser(PCEPRequestMessageParser.TYPE, new PCEPRequestMessageParser(objReg));
+ context.registerMessageParser(PCEPErrorMessageParser.TYPE, new PCEPErrorMessageParser(objReg));
+ context.registerMessageParser(PCEPCloseMessageParser.TYPE, new PCEPCloseMessageParser(objReg));
+ context.registerMessageParser(PCEPUpdateRequestMessageParser.TYPE, new PCEPUpdateRequestMessageParser(objReg));
+ context.registerMessageParser(PCEPReportMessageParser.TYPE, new PCEPReportMessageParser(objReg));
+ context.registerMessageParser(PCCreateMessageParser.TYPE, new PCCreateMessageParser(objReg));
+
+ context.registerMessageSerializer(OpenMessage.class, new PCEPOpenMessageParser(objReg));
+ context.registerMessageSerializer(PcntfMessage.class, new PCEPNotificationMessageParser(objReg));
+ context.registerMessageSerializer(KeepaliveMessage.class, new PCEPKeepAliveMessageParser(objReg));
+ context.registerMessageSerializer(PcrepMessage.class, new PCEPReplyMessageParser(objReg));
+ context.registerMessageSerializer(PcreqMessage.class, new PCEPRequestMessageParser(objReg));
+ context.registerMessageSerializer(PcerrMessage.class, new PCEPErrorMessageParser(objReg));
+ context.registerMessageSerializer(CloseMessage.class, new PCEPCloseMessageParser(objReg));
+ context.registerMessageSerializer(PcupdMessage.class, new PCEPUpdateRequestMessageParser(objReg));
+ context.registerMessageSerializer(PcrptMessage.class, new PCEPReportMessageParser(objReg));
+ context.registerMessageSerializer(PcinitiateMessage.class, new PCCreateMessageParser(objReg));
+
+ this.registrations = regs;
+ }
+
+ @Override
+ public void stop() {
+ Preconditions.checkState(this.registrations != null);
+
+ for (final AutoCloseable r : this.registrations) {
+ try {
+ r.close();
+ } catch (final Exception e) {
+ logger.warn("Failed to close registration", e);
+ }
+ }
+
+ this.registrations = null;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.impl;
+
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.osgi.AbstractOSGiPCEPExtensionProviderActivator;
+
+public final class BundleActivator extends AbstractOSGiPCEPExtensionProviderActivator {
+ private final PCEPExtensionProviderActivator activator = new Activator();
+
+ @Override
+ public void start(final PCEPExtensionProviderContext context) throws Exception {
+ activator.start(context);
+ }
+
+ @Override
+ public void stop() throws Exception {
+ activator.stop();
+ }
+}
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.PCEPDispatcher;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import com.google.common.base.Preconditions;
public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher {
private final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf;
-
- private final PCEPHandlerFactory hf = new PCEPHandlerFactory(SingletonPCEPProviderContext.getInstance().getMessageHandlerRegistry());
+ private final PCEPHandlerFactory hf;
/**
* Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
*
* @throws IOException if some error occurred during opening the selector
*/
- public PCEPDispatcherImpl(final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
+ public PCEPDispatcherImpl(final MessageHandlerRegistry registry, final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
super();
this.snf = Preconditions.checkNotNull(negotiatorFactory);
+ this.hf = new PCEPHandlerFactory(registry);
}
@Override
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.protocol.pcep.impl.message.PCCreateMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPUpdateRequestMessageParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPLspObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelChannelSetParser;
-import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
-import org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROPathKeySubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv4TlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv6TlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.PredundancyGroupTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.PCEPProviderActivator;
-import org.opendaylight.protocol.pcep.spi.PCEPProviderContext;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LoadBalancingObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspErrorCodeTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MetricObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfListTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OrderTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OverloadDurationTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeyObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcepErrorObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcinitiateMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcntfMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrepMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcreqMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrptMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcupdMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PredundancyGroupIdTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReqMissingTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RpObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SvecObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.GeneralizedChannelSetLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.GeneralizedLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.IpPrefixSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Type1Label;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.WavebandSwitchingLabel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-
-public final class PCEPImplActivator implements PCEPProviderActivator {
- private static final Logger logger = LoggerFactory.getLogger(PCEPImplActivator.class);
- private List<AutoCloseable> registrations;
-
- @Override
- public void start(final PCEPProviderContext context) {
- Preconditions.checkState(this.registrations == null);
- final List<AutoCloseable> regs = new ArrayList<>();
-
- final LabelHandlerRegistry labelReg = context.getLabelHandlerRegistry();
- labelReg.registerLabelParser(Type1LabelParser.CTYPE, new Type1LabelParser());
- labelReg.registerLabelParser(GeneralizedLabelParser.CTYPE, new GeneralizedLabelParser());
- labelReg.registerLabelParser(WavebandSwitchingLabelParser.CTYPE, new WavebandSwitchingLabelParser());
- labelReg.registerLabelParser(GeneralizedLabelChannelSetParser.CTYPE, new GeneralizedLabelChannelSetParser());
-
- labelReg.registerLabelSerializer(Type1Label.class, new Type1LabelParser());
- labelReg.registerLabelSerializer(GeneralizedLabel.class, new GeneralizedLabelParser());
- labelReg.registerLabelSerializer(WavebandSwitchingLabel.class, new WavebandSwitchingLabelParser());
- labelReg.registerLabelSerializer(GeneralizedChannelSetLabel.class, new GeneralizedLabelChannelSetParser());
-
- final EROSubobjectHandlerRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
- eroSubReg.registerSubobjectParser(EROIpPrefixSubobjectParser.TYPE, new EROIpPrefixSubobjectParser());
- eroSubReg.registerSubobjectParser(EROIpPrefixSubobjectParser.TYPE6, new EROIpPrefixSubobjectParser());
- eroSubReg.registerSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser());
- eroSubReg.registerSubobjectParser(EROLabelSubobjectParser.TYPE, new EROLabelSubobjectParser(labelReg));
- eroSubReg.registerSubobjectParser(EROUnnumberedInterfaceSubobjectParser.TYPE, new EROUnnumberedInterfaceSubobjectParser());
- eroSubReg.registerSubobjectParser(EROPathKeySubobjectParser.TYPE, new EROPathKeySubobjectParser());
- eroSubReg.registerSubobjectParser(EROPathKeySubobjectParser.TYPE128, new EROPathKeySubobjectParser());
-
- eroSubReg.registerSubobjectSerializer(IpPrefixSubobject.class, new EROIpPrefixSubobjectParser());
- eroSubReg.registerSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser());
- eroSubReg.registerSubobjectSerializer(LabelSubobject.class, new EROLabelSubobjectParser(labelReg));
- eroSubReg.registerSubobjectSerializer(UnnumberedSubobject.class, new EROUnnumberedInterfaceSubobjectParser());
- eroSubReg.registerSubobjectSerializer(PathKeySubobject.class, new EROPathKeySubobjectParser());
-
- final RROSubobjectHandlerRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
- rroSubReg.registerSubobjectParser(RROIpPrefixSubobjectParser.TYPE, new RROIpPrefixSubobjectParser());
- rroSubReg.registerSubobjectParser(RROIpPrefixSubobjectParser.TYPE6, new RROIpPrefixSubobjectParser());
- rroSubReg.registerSubobjectParser(RROLabelSubobjectParser.TYPE, new RROLabelSubobjectParser(labelReg));
- rroSubReg.registerSubobjectParser(RROAsNumberSubobjectParser.TYPE, new RROAsNumberSubobjectParser());
- rroSubReg.registerSubobjectParser(RROUnnumberedInterfaceSubobjectParser.TYPE, new RROUnnumberedInterfaceSubobjectParser());
- rroSubReg.registerSubobjectParser(RROPathKeySubobjectParser.TYPE, new RROPathKeySubobjectParser());
- rroSubReg.registerSubobjectParser(RROPathKeySubobjectParser.TYPE128, new RROPathKeySubobjectParser());
-
- rroSubReg.registerSubobjectSerializer(IpPrefixSubobject.class, new RROIpPrefixSubobjectParser());
- rroSubReg.registerSubobjectSerializer(LabelSubobject.class, new RROLabelSubobjectParser(labelReg));
- rroSubReg.registerSubobjectSerializer(AsNumberSubobject.class, new RROAsNumberSubobjectParser());
- rroSubReg.registerSubobjectSerializer(UnnumberedSubobject.class, new RROUnnumberedInterfaceSubobjectParser());
- rroSubReg.registerSubobjectSerializer(PathKeySubobject.class, new RROPathKeySubobjectParser());
-
- final XROSubobjectHandlerRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
- xroSubReg.registerSubobjectParser(XROIpPrefixSubobjectParser.TYPE, new XROIpPrefixSubobjectParser());
- xroSubReg.registerSubobjectParser(XROIpPrefixSubobjectParser.TYPE6, new XROIpPrefixSubobjectParser());
- xroSubReg.registerSubobjectParser(XROAsNumberSubobjectParser.TYPE, new XROAsNumberSubobjectParser());
- xroSubReg.registerSubobjectParser(XROSRLGSubobjectParser.TYPE, new XROSRLGSubobjectParser());
- xroSubReg.registerSubobjectParser(XROUnnumberedInterfaceSubobjectParser.TYPE, new XROUnnumberedInterfaceSubobjectParser());
- xroSubReg.registerSubobjectParser(XROPathKeySubobjectParser.TYPE, new XROPathKeySubobjectParser());
- xroSubReg.registerSubobjectParser(XROPathKeySubobjectParser.TYPE128, new XROPathKeySubobjectParser());
-
- xroSubReg.registerSubobjectSerializer(IpPrefixSubobject.class, new XROIpPrefixSubobjectParser());
- xroSubReg.registerSubobjectSerializer(AsNumberSubobject.class, new XROAsNumberSubobjectParser());
- xroSubReg.registerSubobjectSerializer(SrlgSubobject.class, new XROSRLGSubobjectParser());
- xroSubReg.registerSubobjectSerializer(UnnumberedSubobject.class, new XROUnnumberedInterfaceSubobjectParser());
- xroSubReg.registerSubobjectSerializer(PathKeySubobject.class, new XROPathKeySubobjectParser());
-
- final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry();
- tlvReg.registerTlvParser(NoPathVectorTlvParser.TYPE, new NoPathVectorTlvParser());
- tlvReg.registerTlvParser(OverloadedDurationTlvParser.TYPE, new OverloadedDurationTlvParser());
- tlvReg.registerTlvParser(ReqMissingTlvParser.TYPE, new ReqMissingTlvParser());
- tlvReg.registerTlvParser(OFListTlvParser.TYPE, new OFListTlvParser());
- tlvReg.registerTlvParser(OrderTlvParser.TYPE, new OrderTlvParser());
- tlvReg.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser());
- tlvReg.registerTlvParser(LspSymbolicNameTlvParser.TYPE, new LspSymbolicNameTlvParser());
- tlvReg.registerTlvParser(LSPIdentifierIPv4TlvParser.TYPE, new LSPIdentifierIPv4TlvParser());
- tlvReg.registerTlvParser(LSPIdentifierIPv6TlvParser.TYPE, new LSPIdentifierIPv6TlvParser());
- tlvReg.registerTlvParser(LspUpdateErrorTlvParser.TYPE, new LspUpdateErrorTlvParser());
- tlvReg.registerTlvParser(RSVPErrorSpecTlvParser.TYPE, new RSVPErrorSpecTlvParser());
- tlvReg.registerTlvParser(LspDbVersionTlvParser.TYPE, new LspDbVersionTlvParser());
- tlvReg.registerTlvParser(PredundancyGroupTlvParser.TYPE, new PredundancyGroupTlvParser());
-
- tlvReg.registerTlvSerializer(NoPathVectorTlv.class, new NoPathVectorTlvParser());
- tlvReg.registerTlvSerializer(OverloadDurationTlv.class, new OverloadedDurationTlvParser());
- tlvReg.registerTlvSerializer(ReqMissingTlv.class, new ReqMissingTlvParser());
- tlvReg.registerTlvSerializer(OfListTlv.class, new OFListTlvParser());
- tlvReg.registerTlvSerializer(OrderTlv.class, new OrderTlvParser());
- tlvReg.registerTlvSerializer(StatefulCapabilityTlv.class, new PCEStatefulCapabilityTlvParser());
- tlvReg.registerTlvSerializer(SymbolicPathNameTlv.class, new LspSymbolicNameTlvParser());
- tlvReg.registerTlvSerializer(LspIdentifiersTlv.class, new LSPIdentifierIPv4TlvParser());
- tlvReg.registerTlvSerializer(LspErrorCodeTlv.class, new LspUpdateErrorTlvParser());
- tlvReg.registerTlvSerializer(RsvpErrorSpecTlv.class, new RSVPErrorSpecTlvParser());
- tlvReg.registerTlvSerializer(LspDbVersionTlv.class, new LspDbVersionTlvParser());
- tlvReg.registerTlvSerializer(PredundancyGroupIdTlv.class, new PredundancyGroupTlvParser());
-
- final ObjectHandlerRegistry objReg = context.getObjectHandlerRegistry();
- objReg.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE,
- new PCEPRequestParameterObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6,
- new PCEPEndPointsObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE,
- new PCEPBandwidthObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(tlvReg));
-
- objReg.registerObjectParser(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE,
- new PCEPExplicitRouteObjectParser(eroSubReg));
- objReg.registerObjectParser(PCEPReportedRouteObjectParser.CLASS, PCEPReportedRouteObjectParser.TYPE,
- new PCEPReportedRouteObjectParser(rroSubReg));
- objReg.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPIncludeRouteObjectParser.CLASS, PCEPIncludeRouteObjectParser.TYPE,
- new PCEPIncludeRouteObjectParser(eroSubReg));
- objReg.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPNotificationObjectParser.CLASS, PCEPNotificationObjectParser.TYPE,
- new PCEPNotificationObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE,
- new PCEPLoadBalancingObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE,
- new PCEPObjectiveFunctionObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(tlvReg));
-
- objReg.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE,
- new PCEPGlobalConstraintsObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(tlvReg));
- objReg.registerObjectParser(PCEPExcludeRouteObjectParser.CLASS, PCEPExcludeRouteObjectParser.TYPE,
- new PCEPExcludeRouteObjectParser(xroSubReg));
-
- objReg.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(tlvReg));
- objReg.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(tlvReg));
- objReg.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(tlvReg));
- objReg.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(tlvReg));
- objReg.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(tlvReg));
- objReg.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(tlvReg));
- objReg.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(eroSubReg));
- objReg.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(rroSubReg));
- objReg.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(tlvReg));
- objReg.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(eroSubReg));
- objReg.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(tlvReg));
- objReg.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(tlvReg));
- objReg.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg));
- objReg.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg));
- objReg.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg));
- objReg.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(tlvReg));
- objReg.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg));
- objReg.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg));
- objReg.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(tlvReg));
- objReg.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(tlvReg));
- objReg.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(tlvReg));
- objReg.registerObjectSerializer(ExcludeRouteObject.class, new PCEPExcludeRouteObjectParser(xroSubReg));
-
- final MessageHandlerRegistry msgReg = context.getMessageHandlerRegistry();
- msgReg.registerMessageParser(PCEPOpenMessageParser.TYPE, new PCEPOpenMessageParser(objReg));
- msgReg.registerMessageParser(PCEPKeepAliveMessageParser.TYPE, new PCEPKeepAliveMessageParser(objReg));
- msgReg.registerMessageParser(PCEPReplyMessageParser.TYPE, new PCEPReplyMessageParser(objReg));
- msgReg.registerMessageParser(PCEPRequestMessageParser.TYPE, new PCEPRequestMessageParser(objReg));
- msgReg.registerMessageParser(PCEPErrorMessageParser.TYPE, new PCEPErrorMessageParser(objReg));
- msgReg.registerMessageParser(PCEPCloseMessageParser.TYPE, new PCEPCloseMessageParser(objReg));
- msgReg.registerMessageParser(PCEPUpdateRequestMessageParser.TYPE, new PCEPUpdateRequestMessageParser(objReg));
- msgReg.registerMessageParser(PCEPReportMessageParser.TYPE, new PCEPReportMessageParser(objReg));
- msgReg.registerMessageParser(PCCreateMessageParser.TYPE, new PCCreateMessageParser(objReg));
-
- msgReg.registerMessageSerializer(OpenMessage.class, new PCEPOpenMessageParser(objReg));
- msgReg.registerMessageSerializer(PcntfMessage.class, new PCEPNotificationMessageParser(objReg));
- msgReg.registerMessageSerializer(KeepaliveMessage.class, new PCEPKeepAliveMessageParser(objReg));
- msgReg.registerMessageSerializer(PcrepMessage.class, new PCEPReplyMessageParser(objReg));
- msgReg.registerMessageSerializer(PcreqMessage.class, new PCEPRequestMessageParser(objReg));
- msgReg.registerMessageSerializer(PcerrMessage.class, new PCEPErrorMessageParser(objReg));
- msgReg.registerMessageSerializer(CloseMessage.class, new PCEPCloseMessageParser(objReg));
- msgReg.registerMessageSerializer(PcupdMessage.class, new PCEPUpdateRequestMessageParser(objReg));
- msgReg.registerMessageSerializer(PcrptMessage.class, new PCEPReportMessageParser(objReg));
- msgReg.registerMessageSerializer(PcinitiateMessage.class, new PCCreateMessageParser(objReg));
-
- this.registrations = regs;
- }
-
- @Override
- public void stop() {
- Preconditions.checkState(this.registrations != null);
-
- for (final AutoCloseable r : this.registrations) {
- try {
- r.close();
- } catch (final Exception e) {
- logger.warn("Failed to close registration", e);
- }
- }
-
- this.registrations = null;
- }
-}
final byte[] retBytes = new byte[headerBytes.length + msgBody.length];
ByteArray.copyWhole(headerBytes, retBytes, 0);
- ByteArray.copyWhole(msgBody, retBytes, PCEPMessageHeader.COMMON_HEADER_LENGTH);
+ ByteArray.copyWhole(msgBody, retBytes, COMMON_HEADER_LENGTH);
return retBytes;
}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl;
-
-import java.util.Arrays;
-
-import org.opendaylight.protocol.util.ByteArray;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.primitives.UnsignedBytes;
-
-/**
- * Header parser for {@link org.opendaylight.protocol.pcep.PCEPMessage PCEPMessage}
- */
-public final class PCEPMessageHeader {
-
- public static final Logger logger = LoggerFactory.getLogger(PCEPMessageHeader.class);
-
- /*
- * lengths of fields in bytes
- */
- private static final int VER_FLAGS_MF_LENGTH = 1;
- private static final int TYPE_F_LENGTH = 1;
- private static final int LENGTH_F_LENGTH = 2;
-
- /*
- * lengths of subfields inside multi-field in bits
- */
- private static final int VERSION_SF_LENGTH = 3;
-
- /*
- * offsets of field in bytes
- */
- private static final int VER_FLAGS_MF_OFFSET = 0;
- private static final int TYPE_F_OFFSET = VER_FLAGS_MF_LENGTH + VER_FLAGS_MF_OFFSET;
- private static final int LENGTH_F_OFFSET = TYPE_F_LENGTH + TYPE_F_OFFSET;
-
- /*
- * offsets of subfields inside multi-filed in bits
- */
-
- private static final int VERSION_SF_OFFSET = 0;
-
- /*
- * COMMON HEADER LENGTH
- */
- public static final int COMMON_HEADER_LENGTH = VER_FLAGS_MF_LENGTH + TYPE_F_LENGTH + LENGTH_F_LENGTH;
-
- private final int type;
- private final int length;
- private final int version;
-
- public PCEPMessageHeader(final int type, final int length, final int version) {
- this.type = type;
- this.length = length;
- this.version = version;
- }
-
- public static PCEPMessageHeader fromBytes(final byte[] bytes) {
- if (bytes == null) {
- throw new IllegalArgumentException("Array of bytes is mandatory");
- }
-
- logger.trace("Attempt to parse message header: {}", ByteArray.bytesToHexString(bytes));
-
- if (bytes.length < COMMON_HEADER_LENGTH) {
- throw new IllegalArgumentException("Too few bytes in passed array. Passed: " + bytes.length + "; Expected: >= " + COMMON_HEADER_LENGTH + ".");
- }
-
- final int type = UnsignedBytes.toInt(bytes[TYPE_F_OFFSET]);
-
- final int length = ByteArray.bytesToInt(Arrays.copyOfRange(bytes,
- LENGTH_F_OFFSET, LENGTH_F_OFFSET + LENGTH_F_LENGTH));
-
- final int version = ByteArray.copyBitsRange(bytes[VER_FLAGS_MF_OFFSET], VERSION_SF_OFFSET, VERSION_SF_LENGTH);
-
- final PCEPMessageHeader ret = new PCEPMessageHeader(type, length, version);
-
- logger.trace("Message header was parsed. {}", ret);
- return ret;
- }
-
- public byte[] toBytes() {
- final byte[] retBytes = new byte[COMMON_HEADER_LENGTH];
-
- // msgVer_Flag
- retBytes[VER_FLAGS_MF_OFFSET] = (byte) (this.version << (Byte.SIZE - VERSION_SF_LENGTH));
-
- // msgType
- retBytes[TYPE_F_OFFSET] = (byte) this.type;
-
- // msgLength
- System.arraycopy(ByteArray.intToBytes(this.length), Integer.SIZE / Byte.SIZE - LENGTH_F_LENGTH, retBytes, LENGTH_F_OFFSET, LENGTH_F_LENGTH);
-
- return retBytes;
- }
-
- public int getLength() {
- return this.length;
- }
-
- public int getVersion() {
- return this.version;
- }
-
- public int getType() {
- return this.type;
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("PCEPMessageHeader [type=");
- builder.append(this.type);
- builder.append(", length=");
- builder.append(this.length);
- builder.append(", version=");
- builder.append(this.version);
- builder.append("]");
- return builder.toString();
- }
-}
package org.opendaylight.protocol.pcep.impl;
import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
import io.netty.util.Timeout;
import io.netty.util.Timer;
import io.netty.util.TimerTask;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.LinkedList;
import java.util.Queue;
+import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.opendaylight.protocol.framework.AbstractProtocolSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Sends message to serialization.
- *
+ *
* @param msg to be sent
*/
@Override
- public void sendMessage(final Message msg) {
- try {
- this.channel.writeAndFlush(msg);
- this.lastMessageSentAt = System.nanoTime();
- if (!(msg instanceof KeepaliveMessage)) {
- logger.debug("Sent message: " + msg);
- }
- this.sentMsgCount++;
- } catch (final Exception e) {
- logger.warn("Message {} was not sent.", msg, e);
+ public Future<Void> sendMessage(final Message msg) {
+ final ChannelFuture f = this.channel.writeAndFlush(msg);
+ this.lastMessageSentAt = System.nanoTime();
+ if (!(msg instanceof KeepaliveMessage)) {
+ logger.debug("Message enqueued: {}", msg);
}
+ this.sentMsgCount++;
+
+ f.addListener(new ChannelFutureListener() {
+ @Override
+ public void operationComplete(final ChannelFuture arg) {
+ if (arg.isSuccess()) {
+ logger.debug("Message sent to socket: {}", msg);
+ } else {
+ logger.debug("Message not sent: {}", msg, arg.cause());
+ }
+ }
+ });
+
+ return f;
}
/**
this.channel.close();
}
+ @Override
+ public Tlvs getRemoteTlvs() {
+ return remoteOpen.getTlvs();
+ }
+
+ @Override
+ public InetAddress getRemoteAddress() {
+ return ((InetSocketAddress) this.channel.remoteAddress()).getAddress();
+ }
+
private synchronized void terminate(final TerminationReason reason) {
this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
this.closed = true;
/**
* Sends PCEP Error Message with one PCEPError and Open Object.
- *
+ *
* @param value
* @param open
*/
* sent (CAPABILITY_NOT_SUPPORTED) and the method checks if the MAX_UNKNOWN_MSG per minute wasn't overstepped.
* Second, any other error occurred that is specified by rfc. In this case, the an error message is generated and
* sent.
- *
+ *
* @param error documented error in RFC5440 or draft
*/
@VisibleForTesting
/**
* Handles incoming message. If the session is up, it notifies the user. The user is notified about every message
* except KeepAlive.
- *
+ *
* @param msg incoming message
*/
@Override
@Override
public String getNodeIdentifier() {
- if (this.remoteOpen.getTlvs() == null)
+ if (this.remoteOpen.getTlvs() == null) {
if (this.remoteOpen.getTlvs().getPredundancyGroupId() != null) {
return new String(this.remoteOpen.getTlvs().getPredundancyGroupId().getIdentifier());
}
+ }
return "";
}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.PCEPProviderContext;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-
-/**
- *
- */
-@ThreadSafe
-public final class SingletonPCEPProviderContext implements PCEPProviderContext {
- private static final class Holder {
- private static final PCEPProviderContext INSTANCE;
-
- static {
- final PCEPProviderContext pc = new SingletonPCEPProviderContext();
- new PCEPImplActivator().start(pc);
- INSTANCE = pc;
- }
- }
-
- private final LabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
- private final MessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
- private final ObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
- private final EROSubobjectHandlerRegistry eroSubReg = new SimpleEROSubobjectHandlerFactory();
- private final RROSubobjectHandlerRegistry rroSubReg = new SimpleRROSubobjectHandlerFactory();
- private final XROSubobjectHandlerRegistry xroSubReg = new SimpleXROSubobjectHandlerFactory();
- private final TlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry();
-
- private SingletonPCEPProviderContext() {
-
- }
-
- public static PCEPProviderContext getInstance() {
- return Holder.INSTANCE;
- }
-
- @Override
- public LabelHandlerRegistry getLabelHandlerRegistry() {
- return labelReg;
- }
-
- @Override
- public MessageHandlerRegistry getMessageHandlerRegistry() {
- return this.msgReg;
- }
-
- @Override
- public ObjectHandlerRegistry getObjectHandlerRegistry() {
- return this.objReg;
- }
-
- @Override
- public EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
- return this.eroSubReg;
- }
-
- @Override
- public RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry() {
- return this.rroSubReg;
- }
-
- @Override
- public XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
- return this.xroSubReg;
- }
-
- @Override
- public TlvHandlerRegistry getTlvHandlerRegistry() {
- return this.tlvReg;
- }
-}
final List<IpAddress> addresses = Lists.newArrayList();
while (bytes.length > offset) {
- if (family instanceof Ipv4)
+ if (family instanceof Ipv4) {
addresses.add(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(bytes, offset, addrLen))));
- else
+ } else {
addresses.add(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, offset, addrLen))));
+ }
offset += addrLen;
}
public static void putAddresses(final byte[] destBytes, int offset, final List<IpAddress> addresses, final int addrLen) {
for (final IpAddress address : addresses) {
- if (address.getIpv4Address() != null)
+ if (address.getIpv4Address() != null) {
System.arraycopy(address.getIpv4Address().getValue().getBytes(), 0, destBytes, offset, addrLen);
- else
+ } else {
System.arraycopy(address.getIpv6Address().getValue().getBytes(), 0, destBytes, offset, addrLen);
+ }
offset += addrLen;
}
}
- public static int getPadding(final int length, final int padding) {
- return (padding - (length % padding)) % padding;
- }
-
public static Message createErrorMessage(final PCEPErrors e, final OpenObject t) {
final PcerrBuilder errMessageBuilder = new PcerrBuilder();
final PCEPErrorMapping mapping = PCEPErrorMapping.getInstance();
final PCEPErrorIdentifier id = mapping.getFromErrorsEnum(e);
final Errors err = new ErrorsBuilder().setType(id.type).setValue(id.value).build();
- if (t == null)
+ if (t == null) {
return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Arrays.asList(err)).build()).build();
- else {
+ } else {
final ErrorType type = new SessionBuilder().setOpen((Open) t).build();
return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Arrays.asList(err)).setErrorType(type).build()).build();
}
* 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.pcep.impl.message;
+package org.opendaylight.protocol.pcep.impl.object;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.ObjectParser;
public abstract void addTlv(final BUILDER builder, final Tlv tlv);
- private static int getPadding(final int length, final int padding) {
+ protected static int getPadding(final int length, final int padding) {
return (padding - (length % padding)) % padding;
}
}
length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
- type = bytes[offset + TYPE_FLAG_F_OFFSET];
+ final boolean mandatory = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+ type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
if (length > bytes.length - offset) {
throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, false);
+ final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, mandatory);
logger.debug("Subobject was parsed. {}", sub);
subs.add(sub);
final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
- final byte typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0]);
+ final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
+ : 0));
final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
bytes[0] = typeBytes;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
@Override
public BandwidthObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
}
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: "
+ BANDWIDTH_F_LENGTH + ".");
}
-
final BandwidthBuilder builder = new BandwidthBuilder();
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
-
builder.setBandwidth(new Float32(bytes));
-
return builder.build();
}
if (!(object instanceof BandwidthObject)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed BandwidthObject.");
}
-
return ((BandwidthObject) object).getBandwidth().getValue();
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.ClassTypeBuilder;
+import com.google.common.primitives.UnsignedBytes;
+
/**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPClassTypeObject PCEPClassTypeObject}
+ * Parser for {@link ClasstypeObject}
*/
public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<ClassTypeBuilder> {
/**
* Length of Class Type field in bits.
*/
- public static final int CT_F_LENGTH = 3;
+ private static final int CT_F_LENGTH = 3;
/**
* Reserved field bit length.
*/
- public static final int RESERVED = 29;
+ private static final int RESERVED = 29;
/**
* Size of the object in bytes.
*/
- public static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
+ private static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
public PCEPClassTypeObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
@Override
public ClasstypeObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null) {
throw new IllegalArgumentException("Byte array is mandatory.");
}
if (!header.isProcessingRule()) {
throw new PCEPDocumentedException("Processed bit not set", PCEPErrors.P_FLAG_NOT_SET);
}
-
final ClassTypeBuilder builder = new ClassTypeBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- final short ct = (short) (bytes[SIZE - 1] & 0xFF);
+ final short ct = (short) UnsignedBytes.toInt(bytes[SIZE - 1]);
builder.setClassType(new ClassType(ct));
if (ct < 0 || ct > 8) {
if (!(object instanceof ClasstypeObject)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed ClasstypeObject.");
}
-
final byte[] retBytes = new byte[SIZE];
- retBytes[SIZE - 1] = ((ClasstypeObject) object).getClassType().getValue().byteValue();
+ retBytes[SIZE - 1] = UnsignedBytes.checkedCast(((ClasstypeObject) object).getClassType().getValue());
return retBytes;
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.Tlvs;
+import com.google.common.primitives.UnsignedBytes;
+
/**
* Parser for {@link org.opendaylight.protocol.pcep.object.PCEPCloseObject PCEPCloseObject}
*/
/*
* lengths of fields in bytes
*/
- public static final int FLAGS_F_LENGTH = 1;
- public static final int REASON_F_LENGTH = 1;
+ private static final int FLAGS_F_LENGTH = 1;
+ private static final int REASON_F_LENGTH = 1;
/*
* offsets of fields in bytes
*/
- public static final int FLAGS_F_OFFSET = 2; // added reserved field of size 2 bytes
- public static final int REASON_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = 2;
+ private static final int REASON_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
/*
* total size of object in bytes
*/
- public static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH;
+ private static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH;
public PCEPCloseObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
if (bytes == null) {
throw new IllegalArgumentException("Byte array is mandatory.");
}
-
final CCloseBuilder builder = new CCloseBuilder();
-
parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
-
- builder.setReason((short) (bytes[REASON_F_OFFSET] & 0xFF));
-
+ builder.setReason((short) UnsignedBytes.toInt(bytes[REASON_F_OFFSET]));
return builder.build();
}
if (!(object instanceof CloseObject)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed CloseObject.");
}
-
final CloseObject obj = (CloseObject) object;
final byte[] tlvs = serializeTlvs(obj.getTlvs());
if (tlvs != null) {
tlvsLength = tlvs.length;
}
- final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+ final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
if (tlvs != null) {
ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
}
-
- final int reason = ((CClose) obj).getReason().intValue();
-
- retBytes[REASON_F_OFFSET] = (byte) reason;
-
+ retBytes[REASON_F_OFFSET] = UnsignedBytes.checkedCast(((CClose) obj).getReason());
return retBytes;
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<EndpointsBuilder> {
public static final int CLASS = 4;
-
public static final int TYPE = 1;
+ public static final int CLASS_6 = 4;
+ public static final int TYPE_6 = 2;
+
/*
* fields lengths and offsets for IPv4 in bytes
*/
- public static final int SRC4_F_LENGTH = 4;
- public static final int DEST4_F_LENGTH = 4;
+ private static final int SRC4_F_LENGTH = 4;
+ private static final int DEST4_F_LENGTH = 4;
- public static final int SRC4_F_OFFSET = 0;
- public static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
-
- public static final int CLASS_6 = 4;
-
- public static final int TYPE_6 = 2;
+ private static final int SRC4_F_OFFSET = 0;
+ private static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
- public static final int SRC6_F_LENGTH = 16;
- public static final int DEST6_F_LENGTH = 16;
+ private static final int SRC6_F_LENGTH = 16;
+ private static final int DEST6_F_LENGTH = 16;
- public static final int SRC6_F_OFFSET = 0;
- public static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
+ private static final int SRC6_F_OFFSET = 0;
+ private static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
public PCEPEndPointsObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
@Override
public EndpointsObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null) {
throw new IllegalArgumentException("Array of bytes is mandatory");
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@Override
public PcepErrorObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null) {
throw new IllegalArgumentException("Array of bytes is mandatory.");
}
if (tlvs != null) {
tlvsLength = tlvs.length;
}
- final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+ final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
if (tlvs != null) {
ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.GcBuilder;
+import com.google.common.primitives.UnsignedBytes;
+
/**
* Parser for {@link GcObject}
*/
public static final int TYPE = 1;
- private final static int MAX_HOP_F_LENGTH = 1;
- private final static int MAX_UTIL_F_LENGTH = 1;
- private final static int MIN_UTIL_F_LENGTH = 1;
- private final static int OVER_BOOKING_FACTOR_F_LENGTH = 1;
+ private static final int MAX_HOP_F_LENGTH = 1;
+ private static final int MAX_UTIL_F_LENGTH = 1;
+ private static final int MIN_UTIL_F_LENGTH = 1;
+ private static final int OVER_BOOKING_FACTOR_F_LENGTH = 1;
- private final static int MAX_HOP_F_OFFSET = 0;
- private final static int MAX_UTIL_F_OFFSET = MAX_HOP_F_OFFSET + MAX_HOP_F_LENGTH;
- private final static int MIN_UTIL_F_OFFSET = MAX_UTIL_F_OFFSET + MAX_UTIL_F_LENGTH;
- private final static int OVER_BOOKING_FACTOR_F_OFFSET = MIN_UTIL_F_OFFSET + MIN_UTIL_F_LENGTH;
+ private static final int MAX_HOP_F_OFFSET = 0;
+ private static final int MAX_UTIL_F_OFFSET = MAX_HOP_F_OFFSET + MAX_HOP_F_LENGTH;
+ private static final int MIN_UTIL_F_OFFSET = MAX_UTIL_F_OFFSET + MAX_UTIL_F_LENGTH;
+ private static final int OVER_BOOKING_FACTOR_F_OFFSET = MIN_UTIL_F_OFFSET + MIN_UTIL_F_LENGTH;
- private final static int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH;
+ private static final int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH;
public PCEPGlobalConstraintsObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
}
-
final GcBuilder builder = new GcBuilder();
- parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- builder.setMaxHop((short) (bytes[MAX_HOP_F_OFFSET] & 0xFF));
- builder.setMinUtilization((short) (bytes[MIN_UTIL_F_OFFSET] & 0xFF));
- builder.setMaxUtilization((short) (bytes[MAX_UTIL_F_OFFSET] & 0xFF));
- builder.setOverBookingFactor((short) (bytes[OVER_BOOKING_FACTOR_F_OFFSET] & 0xFF));
-
+ builder.setMaxHop((short) UnsignedBytes.toInt(bytes[MAX_HOP_F_OFFSET]));
+ builder.setMinUtilization((short) UnsignedBytes.toInt(bytes[MIN_UTIL_F_OFFSET]));
+ builder.setMaxUtilization((short) UnsignedBytes.toInt(bytes[MAX_UTIL_F_OFFSET]));
+ builder.setOverBookingFactor((short) UnsignedBytes.toInt(bytes[OVER_BOOKING_FACTOR_F_OFFSET]));
return builder.build();
}
if (!(object instanceof GcObject)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed GcObject.");
}
-
final GcObject specObj = (GcObject) object;
-
- // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
final byte[] retBytes = new byte[TLVS_OFFSET + 0];
-
- retBytes[MAX_HOP_F_OFFSET] = specObj.getMaxHop().byteValue();
- retBytes[MAX_UTIL_F_OFFSET] = specObj.getMaxUtilization().byteValue();
- retBytes[MIN_UTIL_F_OFFSET] = specObj.getMinUtilization().byteValue();
- retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = specObj.getOverBookingFactor().byteValue();
-
- // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
-
+ retBytes[MAX_HOP_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxHop());
+ retBytes[MAX_UTIL_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxUtilization());
+ retBytes[MIN_UTIL_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMinUtilization());
+ retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getOverBookingFactor());
return retBytes;
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
+import com.google.common.primitives.UnsignedBytes;
+
/**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject PCEPLoadBalancingObject}
+ * Parser for {@link LoadBalancingObject}
*/
public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<LoadBalancingBuilder> {
public static final int TYPE = 1;
- public static final int FLAGS_F_LENGTH = 1;
- public static final int MAX_LSP_F_LENGTH = 1;
- public static final int MIN_BAND_F_LENGTH = 4;
+ private static final int FLAGS_F_LENGTH = 1;
+ private static final int MAX_LSP_F_LENGTH = 1;
+ private static final int MIN_BAND_F_LENGTH = 4;
- public static final int FLAGS_F_OFFSET = 2;
- public static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
- public static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = 2;
+ private static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+ private static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
- public static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
+ private static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
public PCEPLoadBalancingObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
@Override
public LoadBalancingObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
}
-
if (bytes.length != SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: " + SIZE + ".");
}
-
final LoadBalancingBuilder builder = new LoadBalancingBuilder();
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
-
- builder.setMaxLsp((short) (bytes[MAX_LSP_F_OFFSET] & 0xFF));
+ builder.setMaxLsp((short) UnsignedBytes.toInt(bytes[MAX_LSP_F_OFFSET]));
builder.setMinBandwidth(new Float32(ByteArray.subByte(bytes, MIN_BAND_F_OFFSET, MIN_BAND_F_LENGTH)));
-
return builder.build();
}
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
+ ". Needed LoadBalancingObject.");
}
-
final LoadBalancingObject specObj = (LoadBalancingObject) object;
-
final byte[] retBytes = new byte[SIZE];
-
- retBytes[MAX_LSP_F_OFFSET] = ByteArray.shortToBytes(specObj.getMaxLsp())[1];
+ retBytes[MAX_LSP_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxLsp());
ByteArray.copyWhole(specObj.getMinBandwidth().getValue(), retBytes, MIN_BAND_F_OFFSET);
-
return retBytes;
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.LspaBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
+import com.google.common.primitives.UnsignedBytes;
+
/**
* Parser for {@link LspaObject}
*/
/*
* lengths of fields in bytes
*/
- public static final int EXC_ANY_F_LENGTH = 4;
- public static final int INC_ANY_F_LENGTH = 4;
- public static final int INC_ALL_F_LENGTH = 4;
- public static final int SET_PRIO_F_LENGTH = 1;
- public static final int HOLD_PRIO_F_LENGTH = 1;
- public static final int FLAGS_F_LENGTH = 1;
+ private static final int EXC_ANY_F_LENGTH = 4;
+ private static final int INC_ANY_F_LENGTH = 4;
+ private static final int INC_ALL_F_LENGTH = 4;
+ private static final int SET_PRIO_F_LENGTH = 1;
+ private static final int HOLD_PRIO_F_LENGTH = 1;
+ private static final int FLAGS_F_LENGTH = 1;
/*
* offsets of flags inside flags field in bits
*/
- public static final int S_FLAG_OFFSET = 6;
- public static final int L_FLAG_OFFSET = 7;
+ private static final int S_FLAG_OFFSET = 6;
+ private static final int L_FLAG_OFFSET = 7;
/*
* offsets of fields in bytes
*/
- public static final int EXC_ANY_F_OFFSET = 0;
- public static final int INC_ANY_F_OFFSET = EXC_ANY_F_OFFSET + EXC_ANY_F_LENGTH;
- public static final int INC_ALL_F_OFFSET = INC_ANY_F_OFFSET + INC_ANY_F_LENGTH;
- public static final int SET_PRIO_F_OFFSET = INC_ALL_F_OFFSET + INC_ALL_F_LENGTH;
- public static final int HOLD_PRIO_F_OFFSET = SET_PRIO_F_OFFSET + SET_PRIO_F_LENGTH;
- public static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
- public static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B
+ private static final int EXC_ANY_F_OFFSET = 0;
+ private static final int INC_ANY_F_OFFSET = EXC_ANY_F_OFFSET + EXC_ANY_F_LENGTH;
+ private static final int INC_ALL_F_OFFSET = INC_ANY_F_OFFSET + INC_ANY_F_LENGTH;
+ private static final int SET_PRIO_F_OFFSET = INC_ALL_F_OFFSET + INC_ALL_F_LENGTH;
+ private static final int HOLD_PRIO_F_OFFSET = SET_PRIO_F_OFFSET + SET_PRIO_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
+ private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B
public PCEPLspaObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
if (bytes == null) {
throw new IllegalArgumentException("Bytes array is mandatory.");
}
-
final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH));
final LspaBuilder builder = new LspaBuilder();
-
parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_F_OFFSET));
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- builder.setHoldPriority((short) (bytes[HOLD_PRIO_F_OFFSET] & 0xFF));
- builder.setSetupPriority((short) (bytes[SET_PRIO_F_OFFSET] & 0xFF));
+ builder.setHoldPriority((short) UnsignedBytes.toInt(bytes[HOLD_PRIO_F_OFFSET]));
+ builder.setSetupPriority((short) UnsignedBytes.toInt(bytes[SET_PRIO_F_OFFSET]));
builder.setLocalProtectionDesired(flags.get(L_FLAG_OFFSET));
builder.setExcludeAny(new AttributeFilter(ByteArray.bytesToLong(ByteArray.subByte(bytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH))));
builder.setIncludeAll(new AttributeFilter(ByteArray.bytesToLong(ByteArray.subByte(bytes, INC_ALL_F_OFFSET, INC_ALL_F_LENGTH))));
builder.setIncludeAny(new AttributeFilter(ByteArray.bytesToLong(ByteArray.subByte(bytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH))));
-
return builder.build();
}
if (!(object instanceof LspaObject)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed LspaObject.");
}
-
final LspaObject lspaObj = (LspaObject) object;
- // FIXME, but no Tlvs defined
- // final byte[] tlvs = PCEPTlvParser.put(lspaObj.getTlvs());
- // final byte[] retBytes = new byte[TLVS_F_OFFSET + tlvs.length];
- // ByteArray.copyWhole(tlvs, retBytes, TLVS_F_OFFSET);
-
final byte[] retBytes = new byte[TLVS_F_OFFSET];
System.arraycopy(ByteArray.longToBytes(lspaObj.getExcludeAny().getValue()), 4, retBytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH);
System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAny().getValue()), 4, retBytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH);
System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAll().getValue()), 4, retBytes, INC_ALL_F_OFFSET, INC_ALL_F_LENGTH);
- retBytes[SET_PRIO_F_OFFSET] = ByteArray.shortToBytes(lspaObj.getSetupPriority())[Short.SIZE / Byte.SIZE - 1];
- retBytes[HOLD_PRIO_F_OFFSET] = ByteArray.shortToBytes(lspaObj.getHoldPriority())[Short.SIZE / Byte.SIZE - 1];
+ retBytes[SET_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getSetupPriority());
+ retBytes[HOLD_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getHoldPriority());
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
-
return retBytes;
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.Metric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
+import com.google.common.primitives.UnsignedBytes;
+
/**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPMetricObject PCEPMetricObject}
+ * Parser for {@link MetricObject}
*/
public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricBuilder> {
/*
* offsets of fields in bytes
*/
- public static final int FLAGS_F_OFFSET = 2;
- public static final int TYPE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
- public static final int METRIC_VALUE_F_OFFSET = TYPE_F_OFFSET + TYPE_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = 2;
+ private static final int TYPE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+ private static final int METRIC_VALUE_F_OFFSET = TYPE_F_OFFSET + TYPE_F_LENGTH;
/*
* flags offsets inside flags field in bits
private static final int C_FLAG_OFFSET = 6;
private static final int B_FLAG_OFFSET = 7;
- public static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH;
+ private static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH;
public PCEPMetricObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
@Override
public MetricObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
}
}
final byte[] flagBytes = { bytes[FLAGS_F_OFFSET] };
final BitSet flags = ByteArray.bytesToBitSet(flagBytes);
-
final MetricBuilder builder = new MetricBuilder();
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
-
builder.setBound(flags.get(B_FLAG_OFFSET));
builder.setComputed(flags.get(C_FLAG_OFFSET));
- builder.setMetricType((short) (bytes[TYPE_F_OFFSET] & 0xFF));
+ builder.setMetricType((short) UnsignedBytes.toInt(bytes[TYPE_F_OFFSET]));
builder.setValue(new Float32(ByteArray.subByte(bytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH)));
-
return builder.build();
}
if (!(object instanceof MetricObject)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed MetricObject.");
}
-
final MetricObject mObj = (MetricObject) object;
-
final byte[] retBytes = new byte[SIZE];
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
flags.set(C_FLAG_OFFSET, ((Metric) mObj).isComputed());
flags.set(B_FLAG_OFFSET, mObj.isBound());
-
ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
-
+ retBytes[TYPE_F_OFFSET] = UnsignedBytes.checkedCast(mObj.getMetricType());
System.arraycopy(mObj.getValue().getValue(), 0, retBytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH);
-
return retBytes;
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPath;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.Tlvs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPath;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.Tlvs;
/**
* Parser for {@link NoPathObject}
@Override
public NoPathObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
}
if (tlvs != null) {
tlvsLength = tlvs.length;
}
- final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+ final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
if (tlvs != null) {
ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
@Override
public NotificationObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ PCEPDocumentedException {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
}
if (tlvs != null) {
tlvsLength = tlvs.length;
}
- final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+ final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
if (tlvs != null) {
ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
/*
* lengths of fields
*/
- public static final int OF_CODE_F_LENGTH = 2;
+ private static final int OF_CODE_F_LENGTH = 2;
/*
* offsets of fields
*/
- public static final int OF_CODE_F_OFFSET = 0;
- public static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2; // added reserved field of size 2
+ private static final int OF_CODE_F_OFFSET = 0;
+ private static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2;
public PCEPObjectiveFunctionObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
}
-
final OfBuilder builder = new OfBuilder();
-
- parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- builder.setCode(new OfId(ByteArray.bytesToInt(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH)) & 0xFFFF));
-
+ builder.setCode(new OfId(ByteArray.bytesToInt(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH))));
return builder.build();
}
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
+ ". Needed PCEPObjectiveFunction.");
}
-
final OfObject specObj = (OfObject) object;
- // FIXME
- // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
final byte[] retBytes = new byte[TLVS_OFFSET + 0];
-
- // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
-
ByteArray.copyWhole(ByteArray.shortToBytes(specObj.getCode().getValue().shortValue()), retBytes, OF_CODE_F_OFFSET);
-
return retBytes;
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
final byte[] tlvs = serializeTlvs(open.getTlvs());
- final byte[] bytes = new byte[TLVS_OFFSET + tlvs.length + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+ final byte[] bytes = new byte[TLVS_OFFSET + tlvs.length + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
bytes[VER_FLAGS_MF_OFFSET] = versionFlagMF;
bytes[KEEPALIVE_F_OFFSET] = ByteArray.shortToBytes(open.getKeepalive())[1];
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
if (tlvs != null) {
tlvsLength = tlvs.length;
}
- final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+ final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
if (tlvs != null) {
ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
*/
package org.opendaylight.protocol.pcep.impl.object;
+import java.util.Arrays;
+
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.SrpBuilder;
+/**
+ * Parser for {@link SrpObject}
+ */
public final class PCEPSrpObjectParser extends AbstractObjectWithTlvsParser<SrpBuilder> {
public static final int CLASS = 33;
public static final int TYPE = 1;
+ private static final int FLAGS_SIZE = 4;
+
+ private static final int SRP_ID_SIZE = 4;
+
+ private static final int MIN_SIZE = FLAGS_SIZE + SRP_ID_SIZE;
+
public PCEPSrpObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
}
@Override
public SrpObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
-
- // FIXME: finish
-
+ if (bytes == null || bytes.length == 0) {
+ throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+ }
+ if (bytes.length < MIN_SIZE) {
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + MIN_SIZE
+ + ".");
+ }
+ if (header.isProcessingRule()) {
+ throw new PCEPDeserializerException("Processed flag is set");
+ }
final SrpBuilder builder = new SrpBuilder();
-
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
-
+ final byte[] srpId = ByteArray.subByte(bytes, FLAGS_SIZE, SRP_ID_SIZE);
+ if (Arrays.equals(srpId, new byte[] { 0, 0, 0, 0 }) || Arrays.equals(srpId, new byte[] { 0xFFFFFFFF })) {
+ throw new PCEPDeserializerException("Min/Max values for SRP ID are reserved.");
+ }
+ builder.setOperationId(new SrpIdNumber(ByteArray.bytesToLong(srpId)));
return builder.build();
}
if (!(object instanceof SrpObject)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed SrpObject.");
}
-
final SrpObject srp = (SrpObject) object;
- // FIXME: finish
-
- return new byte[0];
+ final Long id = srp.getOperationId().getValue();
+ if (id == 0 || id == 0xFFFFFFFFL) {
+ throw new IllegalArgumentException("Min/Max values for SRP ID are reserved.");
+ }
+ final byte[] retBytes = new byte[MIN_SIZE];
+ System.arraycopy(ByteArray.intToBytes(id.intValue()), 0, retBytes, FLAGS_SIZE, SRP_ID_SIZE);
+ return retBytes;
}
@Override
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
/*
* field lengths in bytes
*/
- public static final int FLAGS_F_LENGTH = 3;
- public static final int REQ_LIST_ITEM_LENGTH = 4;
+ private static final int FLAGS_F_LENGTH = 3;
+ private static final int REQ_LIST_ITEM_LENGTH = 4;
/*
* fields offsets in bytes
*/
- public static final int FLAGS_F_OFFSET = 1; // aded reserved field of size 1
- public static final int REQ_ID_LIST_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = 1;
+ private static final int REQ_ID_LIST_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
/*
* flags offsets inside flags field in bits
*/
- public static final int S_FLAG_OFFSET = 21;
- public static final int N_FLAG_OFFSET = 22;
- public static final int L_FLAG_OFFSET = 23;
+ private static final int S_FLAG_OFFSET = 21;
+ private static final int N_FLAG_OFFSET = 22;
+ private static final int L_FLAG_OFFSET = 23;
/*
* min size in bytes
*/
- public static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
+ private static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
public PCEPSvecObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
}
-
if (bytes.length < MIN_SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + MIN_SIZE
+ ".");
}
-
final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH));
final List<RequestId> requestIDs = Lists.newArrayList();
for (int i = REQ_ID_LIST_OFFSET; i < bytes.length; i += REQ_LIST_ITEM_LENGTH) {
requestIDs.add(new RequestId(ByteArray.bytesToLong(ByteArray.subByte(bytes, i, REQ_LIST_ITEM_LENGTH))));
}
-
if (requestIDs.isEmpty()) {
throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
}
-
final SvecBuilder builder = new SvecBuilder();
builder.setIgnore(header.isIgnore());
System.arraycopy(ByteArray.longToBytes(requestIDs.get(i).getValue()), 4, retBytes, REQ_LIST_ITEM_LENGTH * i
+ REQ_ID_LIST_OFFSET, REQ_LIST_ITEM_LENGTH);
}
-
assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
-
return retBytes;
}
public static final int TYPE = 32;
- public static final int AS_NUMBER_LENGTH = 4;
+ public static final int AS_NUMBER_LENGTH = 2;
public static final int AS_NUMBER_OFFSET = 0;
*/
package org.opendaylight.protocol.pcep.impl.subobject;
+import java.util.List;
+
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.Exrs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder;
+
+import com.google.common.collect.Lists;
public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
public static final int TYPE = 33;
+ private static final int RESERVED = 2;
+
+ private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
+ private static final int SUB_LENGTH_F_LENGTH = 1;
+ private static final int SUB_HEADER_LENGTH = SUB_TYPE_FLAG_F_LENGTH + SUB_LENGTH_F_LENGTH;
+
+ private static final int TYPE_FLAG_F_OFFSET = 0;
+ private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
+ private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
+
+ private final XROSubobjectHandlerRegistry registry;
+
+ public EROExplicitExclusionRouteSubobjectParser(final XROSubobjectHandlerRegistry registry) {
+ this.registry = registry;
+ }
+
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-
- // return new EROExplicitExclusionRouteSubobject(PCEPXROSubobjectParser.parse(cutBytes));
- return null;
+ }
+ final SubobjectsBuilder builder = new SubobjectsBuilder();
+ builder.setLoose(loose);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> list = parseSubobjects(buffer);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs> exrss = Lists.newArrayList();
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects s : list) {
+ final ExrsBuilder b = new ExrsBuilder();
+ b.setAttribute(s.getAttribute());
+ b.setMandatory(s.isMandatory());
+ b.setSubobjectType(s.getSubobjectType());
+ exrss.add(b.build());
+ }
+ builder.setSubobjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.ExrsBuilder().setExrs(
+ exrss).build());
+ return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- // return PCEPXROSubobjectParser.put(subobject.getXroSubobjets());
- return new byte[0];
+ if (!(subobject.getSubobjectType() instanceof Exrs)) {
+ throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getSubobjectType().getClass()
+ + ". Needed Exrs.");
+ }
+ final Exrs e = (Exrs) subobject.getSubobjectType();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> list = Lists.newArrayList();
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs ex : e.getExrs()) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder();
+ b.setAttribute(ex.getAttribute());
+ b.setMandatory(ex.isMandatory());
+ b.setSubobjectType(ex.getSubobjectType());
+ list.add(b.build());
+ }
+ return serializeSubobject(list);
+ }
+
+ private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> parseSubobjects(
+ final byte[] bytes) throws PCEPDeserializerException {
+ if (bytes == null) {
+ throw new IllegalArgumentException("Byte array is mandatory.");
+ }
+
+ int type;
+
+ byte[] soContentsBytes;
+ int length;
+ int offset = 0;
+
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> subs = Lists.newArrayList();
+
+ while (offset < bytes.length) {
+
+ length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
+
+ final boolean mandatory = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+ type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
+ if (length > bytes.length - offset) {
+ throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
+ + (bytes.length - offset));
+ }
+
+ soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
+ System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
+
+ final XROSubobjectParser parser = this.registry.getSubobjectParser(type);
+
+ subs.add(parser.parseSubobject(soContentsBytes, mandatory));
+
+ offset += length;
+ }
+ return subs;
+ }
+
+ private final byte[] serializeSubobject(
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> subobjects) {
+
+ final List<byte[]> result = Lists.newArrayList();
+
+ int finalLength = 0;
+
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects subobject : subobjects) {
+
+ final XROSubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject);
+
+ System.out.println(serializer);
+
+ final byte[] valueBytes = serializer.serializeSubobject(subobject);
+
+ final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
+
+ final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
+ : 0));
+ final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
+
+ bytes[0] = typeBytes;
+ bytes[1] = lengthBytes;
+ System.arraycopy(valueBytes, 0, bytes, SUB_HEADER_LENGTH, valueBytes.length);
+
+ finalLength += bytes.length;
+ result.add(bytes);
+ }
+
+ final byte[] resultBytes = new byte[finalLength];
+ int byteOffset = 0;
+ for (final byte[] b : result) {
+ System.arraycopy(b, 0, resultBytes, byteOffset, b.length);
+ byteOffset += b.length;
+ }
+ return resultBytes;
}
@Override
public static final int TYPE6 = 2;
- public static final int IP4_F_LENGTH = 4;
- public static final int PREFIX4_F_LENGTH = 1;
+ private static final int IP4_F_LENGTH = 4;
+ private static final int PREFIX4_F_LENGTH = 1;
- public static final int PREFIX4_F_OFFSET = IP4_F_LENGTH;
+ private static final int PREFIX4_F_OFFSET = IP4_F_LENGTH;
- public static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX4_F_LENGTH + 1; // added reserved field of size 1
+ private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX4_F_LENGTH + 1;
- public static final int IP_F_LENGTH = 16;
- public static final int PREFIX_F_LENGTH = 1;
+ private static final int IP_F_LENGTH = 16;
+ private static final int PREFIX_F_LENGTH = 1;
- public static final int IP_F_OFFSET = 0;
- public static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
+ private static final int IP_F_OFFSET = 0;
+ private static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
- public static final int CONTENT_LENGTH = PREFIX_F_OFFSET + PREFIX_F_LENGTH + 1; // added reserved field of size 1
- // byte
+ private static final int CONTENT_LENGTH = PREFIX_F_OFFSET + PREFIX_F_LENGTH + 1;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
if (prefix.getIpv4Prefix() != null) {
final byte[] retBytes = new byte[CONTENT4_LENGTH];
- ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, 0);
- retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+ ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, 0);
+ retBytes[PREFIX4_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
return retBytes;
} else if (prefix.getIpv6Prefix() != null) {
final byte[] retBytes = new byte[CONTENT_LENGTH];
- ByteArray.copyWhole(prefix.getIpv6Prefix().getValue().getBytes(), retBytes, 0);
- retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+ ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, 0);
+ retBytes[PREFIX_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
return retBytes;
}
throw new IllegalArgumentException("No valid IpPrefix");
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Label;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
import com.google.common.base.Preconditions;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length < HEADER_LENGTH)
+ }
+ if (buffer.length < HEADER_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
+ HEADER_LENGTH + ".");
-
+ }
final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
if (parser == null) {
throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
}
-
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
builder.setLabelType(parser.parseLabel(ByteArray.cutBytes(buffer, HEADER_LENGTH)));
public byte[] serializeSubobject(final Subobjects subobject) {
Preconditions.checkNotNull(subobject.getSubobjectType(), "Subobject type cannot be empty.");
- final LabelSubobject label = (LabelSubobject) subobject.getSubobjectType();
-
- final LabelSerializer serializer = this.registry.getLabelSerializer((CLabel) label);
+ final Label label = (Label) subobject.getSubobjectType();
+ final LabelType l = label.getLabelType();
- if (serializer == null)
- throw new IllegalArgumentException("Unknown EROLabelSubobject instance. Passed " + label.getClass());
-
- final byte[] labelbytes = serializer.serializeSubobject((CLabel) label);
+ final LabelSerializer serializer = this.registry.getLabelSerializer(l);
+ if (serializer == null) {
+ throw new IllegalArgumentException("Unknown EROLabelSubobject instance. Passed "
+ + label.getLabelType().getImplementedInterface());
+ }
+ final byte[] labelbytes = serializer.serializeLabel(l);
final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
final BitSet reserved = new BitSet();
reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
-
retBytes[C_TYPE_F_OFFSET] = (byte) serializer.getType();
-
return retBytes;
}
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
+/**
+ * Parser for {@link PathKeySubobject}
+ */
public class EROPathKeySubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
public static final int TYPE = 64;
public static final int TYPE128 = 65;
- public static final int PK_F_LENGTH = 2;
- public static final int PCE_ID_F_LENGTH = 4;
+ private static final int PK_F_LENGTH = 2;
+ private static final int PCE_ID_F_LENGTH = 4;
- public static final int PCE128_ID_F_LENGTH = 16;
+ private static final int PCE128_ID_F_LENGTH = 16;
- public static final int PK_F_OFFSET = 0;
- public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
+ private static final int PK_F_OFFSET = 0;
+ private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
- public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ byte[] pceId = null;
+ if (buffer.length == CONTENT_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
+ } else if (buffer.length == CONTENT128_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT128_LENGTH);
+ } else {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
+ CONTENT_LENGTH + ".");
-
- final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
-
- final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
-
+ }
+ final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET));
final SubobjectsBuilder builder = new SubobjectsBuilder();
builder.setLoose(loose);
- // builder.setSubobjectType(value);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(pceId));
+ pBuilder.setPathKey(new PathKey(pathKey));
+ builder.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- final byte[] retBytes = new byte[CONTENT_LENGTH];
-
- // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
- // PK_F_LENGTH);
- //
- // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
- // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
- // ". Expected: ="
- // + PCE_ID_F_LENGTH);
- // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
-
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey pk = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey) subobject.getSubobjectType();
+ final int pathKey = pk.getPathKey().getPathKey().getValue();
+ final byte[] pceId = pk.getPathKey().getPceId().getBinary();
+ final byte[] retBytes = new byte[PK_F_LENGTH + pceId.length];
+ System.arraycopy(ByteArray.shortToBytes((short) pathKey), 0, retBytes, PK_F_OFFSET, PK_F_LENGTH);
+ System.arraycopy(pceId, 0, retBytes, PCE_ID_F_OFFSET, pceId.length);
return retBytes;
}
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ if (buffer.length != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
builder.setLoose(loose);
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject))
+ if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject)) {
throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed UnnumberedSubobject.");
-
+ }
byte[] retBytes;
retBytes = new byte[CONTENT_LENGTH];
final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
-
- ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId()), retBytes, ROUTER_ID_NUMBER_OFFSET);
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
+ ROUTER_ID_NUMBER_OFFSET);
System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
-
return retBytes;
}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl.subobject;
-
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.LabelParser;
-import org.opendaylight.protocol.pcep.spi.LabelSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedChannelSetLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedChannelSetLabelBuilder;
-
-public class GeneralizedLabelChannelSetParser implements LabelParser, LabelSerializer {
-
- public static final int CTYPE = 4;
-
- @Override
- public GeneralizedChannelSetLabel parseLabel(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
- throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- // FIXME: finish
- return new GeneralizedChannelSetLabelBuilder().build();
- }
-
- @Override
- public byte[] serializeSubobject(final CLabel subobject) {
- if (!(subobject instanceof GeneralizedChannelSetLabel))
- throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
- + ". Needed GeneralizedChannelSetLabel.");
- // FIXME: finish
- return new byte[0];
- }
-
- @Override
- public int getType() {
- return CTYPE;
- }
-}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.GeneralizedLabel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
+/**
+ * Parser for {@link GeneralizedLabel}
+ */
public class GeneralizedLabelParser implements LabelParser, LabelSerializer {
public static final int CTYPE = 2;
@Override
public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+ }
return new GeneralizedLabelBuilder().setGeneralizedLabel(buffer).build();
}
@Override
- public byte[] serializeSubobject(final CLabel subobject) {
- if (!(subobject instanceof GeneralizedLabel))
+ public byte[] serializeLabel(final LabelType subobject) {
+ if (!(subobject instanceof GeneralizedLabel)) {
throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
+ ". Needed GeneralizedLabel.");
- return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel) subobject).getGeneralizedLabel();
+ }
+ return ((GeneralizedLabel) subobject).getGeneralizedLabel();
}
@Override
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl.subobject;
-
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.SubobjectType;
-
-/**
- * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROAsNumberSubobject RROAsNumberSubobject}
- */
-
-public class RROAsNumberSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
-
- public static final int TYPE = 32;
-
- public static final int AS_NUMBER_LENGTH = 2;
-
- public static final int AS_NUMBER_OFFSET = 0;
-
- public static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
-
- @Override
- public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
- throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
- + CONTENT_LENGTH + ".");
-
- return new SubobjectsBuilder().setSubobjectType(
- (SubobjectType) new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build()).build();
- }
-
- @Override
- public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof AsNumberSubobject))
- throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
- + ". Needed AsNumberSubobject.");
-
- final byte[] retBytes = new byte[CONTENT_LENGTH];
-
- final AsNumberSubobject obj = (AsNumberSubobject) subobject.getSubobjectType();
-
- System.arraycopy(ByteArray.longToBytes(obj.getAsNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes,
- AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
-
- return retBytes;
- }
-
- @Override
- public int getType() {
- return TYPE;
- }
-}
import java.util.BitSet;
import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
public static final int TYPE6 = 2;
- public static final int IP4_F_LENGTH = 4;
- public static final int PREFIX4_F_LENGTH = 1;
- public static final int FLAGS4_F_LENGTH = 1;
+ private static final int IP4_F_LENGTH = 4;
+ private static final int IP_F_LENGTH = 16;
- public static final int IP4_F_OFFSET = 0;
- public static final int PREFIX4_F_OFFSET = IP4_F_OFFSET + IP4_F_LENGTH;
- public static final int FLAGS4_F_OFFSET = PREFIX4_F_OFFSET + PREFIX4_F_LENGTH;
+ private static final int PREFIX_F_LENGTH = 1;
+ private static final int FLAGS_F_LENGTH = 1;
- public static final int CONTENT4_LENGTH = FLAGS4_F_OFFSET + FLAGS4_F_LENGTH;
+ private static final int IP_F_OFFSET = 0;
- public static final int IP_F_LENGTH = 16;
- public static final int PREFIX_F_LENGTH = 1;
- public static final int FLAGS_F_LENGTH = 1;
+ private static final int PREFIX4_F_OFFSET = IP_F_OFFSET + IP4_F_LENGTH;
+ private static final int FLAGS4_F_OFFSET = PREFIX4_F_OFFSET + PREFIX_F_LENGTH;
- public static final int IP_F_OFFSET = 0;
- public static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
- public static final int FLAGS_F_OFFSET = PREFIX_F_OFFSET + PREFIX_F_LENGTH;
+ private static final int CONTENT4_LENGTH = IP4_F_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
- public static final int CONTENT_LENGTH = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+ private static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = PREFIX_F_OFFSET + PREFIX_F_LENGTH;
- /*
- * flags offset in bits
- */
- public static final int LPA_F_OFFSET = 7;
- public static final int LPIU_F_OFFSET = 6;
+ private static final int CONTENT_LENGTH = IP_F_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
+
+ private static final int LPA_F_OFFSET = 7;
+ private static final int LPIU_F_OFFSET = 6;
@Override
public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT4_LENGTH || buffer.length != CONTENT_LENGTH)
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
-
- final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
-
- final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS4_F_OFFSET, FLAGS4_F_OFFSET + FLAGS4_F_LENGTH));
-
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
- builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
- builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
- builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
- new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP4_F_OFFSET, IP4_F_LENGTH), length))).build());
-
+ if (buffer.length == CONTENT4_LENGTH) {
+ final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
+ final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS4_F_OFFSET, FLAGS4_F_OFFSET + FLAGS_F_LENGTH));
+ builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+ builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
+ builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP4_F_LENGTH), length))).build());
+ } else if (buffer.length == CONTENT_LENGTH) {
+ final int length = UnsignedBytes.toInt(buffer[PREFIX_F_OFFSET]);
+ final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS_F_OFFSET, FLAGS_F_OFFSET + FLAGS_F_LENGTH));
+ builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+ builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
+ builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP_F_LENGTH), length))).build());
+ } else {
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
+ }
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject instanceof IpPrefixSubobject))
+ if (!(subobject.getSubobjectType() instanceof IpPrefixSubobject)) {
throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getClass()
+ ". Needed RROIPAddressSubobject.");
+ }
- final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject;
+ final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject.getSubobjectType();
final IpPrefix prefix = specObj.getIpPrefix();
- if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null)
+ if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null) {
throw new IllegalArgumentException("Unknown AbstractPrefix instance. Passed " + prefix.getClass() + ".");
+ }
- final BitSet flags = new BitSet(FLAGS4_F_LENGTH * Byte.SIZE);
-
+ final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
- final byte[] retBytes = new byte[CONTENT4_LENGTH];
-
if (prefix.getIpv4Prefix() != null) {
- ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, IP4_F_OFFSET);
- retBytes[PREFIX4_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
- ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS4_F_LENGTH), retBytes, FLAGS4_F_OFFSET);
+ final byte[] retBytes = new byte[CONTENT4_LENGTH];
+ ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, IP_F_OFFSET);
+ retBytes[PREFIX4_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
+ ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS4_F_OFFSET);
+ return retBytes;
} else {
- ByteArray.copyWhole(prefix.getIpv6Prefix().getValue().getBytes(), retBytes, IP_F_OFFSET);
- retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+ final byte[] retBytes = new byte[CONTENT_LENGTH];
+ ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, IP_F_OFFSET);
+ retBytes[PREFIX_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
+ return retBytes;
}
- return retBytes;
}
@Override
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.Label;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.LabelBuilder;
import com.google.common.base.Preconditions;
public static final int HEADER_LENGTH = C_TYPE_F_OFFSET + C_TYPE_F_LENGTH;
public static final int U_FLAG_OFFSET = 0;
+ public static final int G_FLAG_OFFSET = 7;
private final LabelHandlerRegistry registry;
@Override
public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length < HEADER_LENGTH)
+ }
+ if (buffer.length < HEADER_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
+ HEADER_LENGTH + ".");
-
+ }
final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
if (parser == null) {
throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
}
-
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
+ builder.setGlobal(reserved.get(G_FLAG_OFFSET));
builder.setLabelType(parser.parseLabel(ByteArray.cutBytes(buffer, HEADER_LENGTH)));
return new SubobjectsBuilder().setSubobjectType(builder.build()).build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- final LabelSubobject label = (LabelSubobject) subobject.getSubobjectType();
- final LabelSerializer parser = this.registry.getLabelSerializer((CLabel) label);
-
- if (parser == null)
+ final Label label = (Label) subobject.getSubobjectType();
+ final LabelType l = label.getLabelType();
+ final LabelSerializer parser = this.registry.getLabelSerializer(l);
+ if (parser == null) {
throw new IllegalArgumentException("Unknown RROLabelSubobject instance. Passed " + subobject.getSubobjectType().getClass());
-
- final byte[] labelbytes = parser.serializeSubobject((CLabel) label);
-
+ }
+ final byte[] labelbytes = parser.serializeLabel(l);
final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
-
System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
final BitSet reserved = new BitSet();
reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
+ reserved.set(G_FLAG_OFFSET, label.isGlobal());
System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
-
retBytes[C_TYPE_F_OFFSET] = (byte) parser.getType();
-
return retBytes;
}
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKeyBuilder;
public class RROPathKeySubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
public static final int TYPE128 = 65;
- public static final int PK_F_LENGTH = 2;
- public static final int PCE_ID_F_LENGTH = 4;
+ private static final int PK_F_LENGTH = 2;
+ private static final int PCE_ID_F_LENGTH = 4;
- public static final int PCE128_ID_F_LENGTH = 16;
+ private static final int PCE128_ID_F_LENGTH = 16;
- public static final int PK_F_OFFSET = 0;
- public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
+ private static final int PK_F_OFFSET = 0;
+ private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
- public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ byte[] pceId = null;
+ if (buffer.length == CONTENT_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
+ } else if (buffer.length == CONTENT128_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT128_LENGTH);
+ } else {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
+ CONTENT_LENGTH + ".");
-
- final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
-
- final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
-
+ }
+ final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET));
final SubobjectsBuilder builder = new SubobjectsBuilder();
- // builder.setSubobjectType(value);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(pceId));
+ pBuilder.setPathKey(new PathKey(pathKey));
+ builder.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- final byte[] retBytes = new byte[CONTENT_LENGTH];
-
- // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
- // PK_F_LENGTH);
- //
- // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
- // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
- // ". Expected: ="
- // + PCE_ID_F_LENGTH);
- // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
-
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKey pk = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKey) subobject.getSubobjectType();
+ final int pathKey = pk.getPathKey().getPathKey().getValue();
+ final byte[] pceId = pk.getPathKey().getPceId().getBinary();
+ final byte[] retBytes = new byte[PK_F_LENGTH + pceId.length];
+ System.arraycopy(ByteArray.shortToBytes((short) pathKey), 0, retBytes, PK_F_OFFSET, PK_F_LENGTH);
+ System.arraycopy(pceId, 0, retBytes, PCE_ID_F_OFFSET, pceId.length);
return retBytes;
}
*/
package org.opendaylight.protocol.pcep.impl.subobject;
+import java.util.Arrays;
+import java.util.BitSet;
+
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import com.google.common.primitives.UnsignedInts;
/**
- * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject
- * RROUnnumberedInterfaceSubobject}
+ * Parser for {@link UnnumberedSubobject}
*/
public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
public static final int TYPE = 4;
- public static final int ROUTER_ID_NUMBER_LENGTH = 4;
- public static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+ private static final int FLAGS_F_LENGTH = 1;
+ private static final int ROUTER_ID_NUMBER_LENGTH = 4;
+ private static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+
+ private static final int ROUTER_ID_NUMBER_OFFSET = 2;
+ private static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
- public static final int ROUTER_ID_NUMBER_OFFSET = 2; // added reserved field of size 2
- public static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
+ private static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
- public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
+ private static final int LPA_F_OFFSET = 7;
+ private static final int LPIU_F_OFFSET = 6;
@Override
public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ if (buffer.length != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
+ final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, 0, FLAGS_F_LENGTH));
+ builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+ builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
ubuilder.setRouterId(ByteArray.bytesToLong(ByteArray.subByte(buffer, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)));
ubuilder.setInterfaceId(UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(buffer, INTERFACE_ID_NUMBER_OFFSET,
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject))
+ if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject)) {
throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed UnnumberedSubobject.");
-
- byte[] retBytes;
- retBytes = new byte[CONTENT_LENGTH];
+ }
+ final byte[] retBytes = new byte[CONTENT_LENGTH];
final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
-
- ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId()), retBytes, ROUTER_ID_NUMBER_OFFSET);
+ final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
+ flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
+ flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
+ retBytes[0] = ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH)[0];
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
+ ROUTER_ID_NUMBER_OFFSET);
System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
-
return retBytes;
}
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Type1Label;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1Label;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelBuilder;
import com.google.common.primitives.UnsignedInts;
@Override
public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != LABEL_LENGTH)
+ }
+ if (buffer.length != LABEL_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: " + LABEL_LENGTH
+ ".");
-
+ }
return new Type1LabelBuilder().setType1Label(UnsignedInts.toLong(ByteArray.bytesToInt(buffer))).build();
}
@Override
- public byte[] serializeSubobject(final CLabel subobject) {
- if (!(subobject instanceof Type1Label))
+ public byte[] serializeLabel(final LabelType subobject) {
+ if (!(subobject instanceof Type1Label)) {
throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass() + ". Needed Type1Label.");
-
- return ByteArray.longToBytes(((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1Label) subobject).getType1Label().longValue());
+ }
+ return ByteArray.subByte(ByteArray.longToBytes(((Type1Label) subobject).getType1Label().longValue()), 4, LABEL_LENGTH);
}
@Override
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.WavebandSwitchingLabel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabelBuilder;
+/**
+ * Parser for {@link WavebandSwitchingLabel}
+ */
public class WavebandSwitchingLabelParser implements LabelParser, LabelSerializer {
public static final int CTYPE = 3;
- private static int WAVEB_F_LENGTH = 4;
- private static int START_F_LENGTH = 4;
- private static int END_F_LENGTH = 4;
+ private static final int WAVEB_F_LENGTH = 4;
+ private static final int START_F_LENGTH = 4;
+ private static final int END_F_LENGTH = 4;
- private static int CONTENT_LENGTH = WAVEB_F_LENGTH + START_F_LENGTH + END_F_LENGTH;
+ private static final int CONTENT_LENGTH = WAVEB_F_LENGTH + START_F_LENGTH + END_F_LENGTH;
@Override
- public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ public WavebandSwitchingLabel parseLabel(final byte[] buffer) throws PCEPDeserializerException {
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-
- if (buffer.length != CONTENT_LENGTH)
+ }
+ if (buffer.length != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
-
+ }
final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
-
int byteOffset = 0;
builder.setWavebandId(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, WAVEB_F_LENGTH)));
byteOffset += WAVEB_F_LENGTH;
builder.setStartLabel(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, START_F_LENGTH)));
byteOffset += START_F_LENGTH;
builder.setEndLabel(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, END_F_LENGTH)));
-
return builder.build();
}
@Override
- public byte[] serializeSubobject(final CLabel subobject) {
- if (!(subobject instanceof WavebandSwitchingLabel))
+ public byte[] serializeLabel(final LabelType subobject) {
+ if (!(subobject instanceof WavebandSwitchingLabel)) {
throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
+ ". Needed WavebandSwitchingLabel.");
+ }
final byte[] retBytes = new byte[CONTENT_LENGTH];
-
final WavebandSwitchingLabel obj = (WavebandSwitchingLabel) subobject;
-
System.arraycopy(ByteArray.intToBytes(obj.getWavebandId().intValue()), 0, retBytes, 0, WAVEB_F_LENGTH);
System.arraycopy(ByteArray.intToBytes(obj.getStartLabel().intValue()), 0, retBytes, WAVEB_F_LENGTH, START_F_LENGTH);
System.arraycopy(ByteArray.intToBytes(obj.getEndLabel().intValue()), 0, retBytes, WAVEB_F_LENGTH + START_F_LENGTH, END_F_LENGTH);
-
return retBytes;
}
/**
* Parser for {@link AsNumberSubobject}
*/
-
public class XROAsNumberSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
public static final int TYPE = 32;
- public static final int AS_NUMBER_LENGTH = 2;
+ private static final int AS_NUMBER_LENGTH = 2;
- public static final int AS_NUMBER_OFFSET = 0;
+ private static final int AS_NUMBER_OFFSET = 0;
- public static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
+ private static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ if (buffer.length != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
-
+ }
return new SubobjectsBuilder().setMandatory(mandatory).setSubobjectType(
new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build()).build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof AsNumberSubobject))
+ if (!(subobject.getSubobjectType() instanceof AsNumberSubobject)) {
throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed AsNumberSubobject.");
-
+ }
final byte[] retBytes = new byte[CONTENT_LENGTH];
-
final AsNumberSubobject obj = (AsNumberSubobject) subobject.getSubobjectType();
-
System.arraycopy(ByteArray.longToBytes(obj.getAsNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes,
AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
-
return retBytes;
}
package org.opendaylight.protocol.pcep.impl.subobject;
import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
public static final int TYPE6 = 2;
- public static final int IP4_F_LENGTH = 4;
- public static final int PREFIX_F_LENGTH = 1;
- public static final int ATTRIBUTE_LENGTH = 1;
+ private static final int IP4_F_LENGTH = 4;
+ private static final int PREFIX_F_LENGTH = 1;
+ private static final int ATTRIBUTE_LENGTH = 1;
- public static final int IP_F_OFFSET = 0;
- public static final int PREFIX4_F_OFFSET = IP_F_OFFSET + IP4_F_LENGTH;
- public static final int ATTRIBUTE4_OFFSET = PREFIX4_F_OFFSET + PREFIX_F_LENGTH;
+ private static final int IP_F_OFFSET = 0;
+ private static final int PREFIX4_F_OFFSET = IP_F_OFFSET + IP4_F_LENGTH;
+ private static final int ATTRIBUTE4_OFFSET = PREFIX4_F_OFFSET + PREFIX_F_LENGTH;
- public static final int CONTENT4_LENGTH = ATTRIBUTE4_OFFSET + ATTRIBUTE_LENGTH;
+ private static final int CONTENT4_LENGTH = ATTRIBUTE4_OFFSET + ATTRIBUTE_LENGTH;
- public static final int IP6_F_LENGTH = 16;
- public static final int PREFIX6_F_OFFSET = IP_F_OFFSET + IP6_F_LENGTH;
- public static final int ATTRIBUTE6_OFFSET = PREFIX6_F_OFFSET + PREFIX_F_LENGTH;
+ private static final int IP6_F_LENGTH = 16;
+ private static final int PREFIX6_F_OFFSET = IP_F_OFFSET + IP6_F_LENGTH;
+ private static final int ATTRIBUTE6_OFFSET = PREFIX6_F_OFFSET + PREFIX_F_LENGTH;
- public static final int CONTENT6_LENGTH = ATTRIBUTE6_OFFSET + ATTRIBUTE_LENGTH;
+ private static final int CONTENT6_LENGTH = ATTRIBUTE6_OFFSET + ATTRIBUTE_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT4_LENGTH && buffer.length != CONTENT6_LENGTH)
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
-
- final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
-
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
builder.setMandatory(mandatory);
- builder.setAttribute(Attribute.forValue(buffer[ATTRIBUTE4_OFFSET] & 0xFF));
- builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
- new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP4_F_LENGTH), length))).build());
+ if (buffer.length == CONTENT4_LENGTH) {
+ final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
+ builder.setAttribute(Attribute.forValue(UnsignedBytes.toInt(buffer[ATTRIBUTE4_OFFSET])));
+ builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP4_F_LENGTH), length))).build());
+ } else if (buffer.length == CONTENT6_LENGTH) {
+ final int length = UnsignedBytes.toInt(buffer[PREFIX6_F_OFFSET]);
+ builder.setAttribute(Attribute.forValue(UnsignedBytes.toInt(buffer[ATTRIBUTE6_OFFSET])));
+ builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP6_F_LENGTH), length))).build());
+ } else {
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
+ }
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof IpPrefixSubobject))
+ if (!(subobject.getSubobjectType() instanceof IpPrefixSubobject)) {
throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed IpPrefixSubobject.");
+ }
final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject.getSubobjectType();
final IpPrefix prefix = specObj.getIpPrefix();
- if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null)
+ if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null) {
throw new IllegalArgumentException("Unknown AbstractPrefix instance. Passed " + prefix.getClass() + ".");
+ }
if (prefix.getIpv4Prefix() != null) {
final byte[] retBytes = new byte[CONTENT4_LENGTH];
- ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, IP_F_OFFSET);
+ ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, IP_F_OFFSET);
retBytes[PREFIX4_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+ retBytes[ATTRIBUTE4_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
return retBytes;
} else {
final byte[] retBytes = new byte[CONTENT6_LENGTH];
- ByteArray.copyWhole(prefix.getIpv6Prefix().getValue().getBytes(), retBytes, IP_F_OFFSET);
+ ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, IP_F_OFFSET);
retBytes[PREFIX6_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+ retBytes[ATTRIBUTE6_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
return retBytes;
}
}
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
+/**
+ * Parser for {@link PathKeySubobject}
+ */
public class XROPathKeySubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
public static final int TYPE = 64;
public static final int TYPE128 = 65;
- public static final int PK_F_LENGTH = 2;
- public static final int PCE_ID_F_LENGTH = 4;
+ private static final int PK_F_LENGTH = 2;
+ private static final int PCE_ID_F_LENGTH = 4;
- public static final int PCE128_ID_F_LENGTH = 16;
+ private static final int PCE128_ID_F_LENGTH = 16;
- public static final int PK_F_OFFSET = 0;
- public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
+ private static final int PK_F_OFFSET = 0;
+ private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
- public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ byte[] pceId = null;
+ if (buffer.length == CONTENT_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
+ } else if (buffer.length == CONTENT128_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT128_LENGTH);
+ } else {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
+ CONTENT_LENGTH + ".");
-
- final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
-
- final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
-
+ }
+ final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET));
final SubobjectsBuilder builder = new SubobjectsBuilder();
- // builder.setSubobjectType(value);
+ builder.setMandatory(mandatory);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(pceId));
+ pBuilder.setPathKey(new PathKey(pathKey));
+ builder.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- final byte[] retBytes = new byte[CONTENT_LENGTH];
-
- // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
- // PK_F_LENGTH);
- //
- // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
- // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
- // ". Expected: ="
- // + PCE_ID_F_LENGTH);
- // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
-
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey pk = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey) subobject.getSubobjectType();
+ final int pathKey = pk.getPathKey().getPathKey().getValue();
+ final byte[] pceId = pk.getPathKey().getPceId().getBinary();
+ final byte[] retBytes = new byte[PK_F_LENGTH + pceId.length];
+ System.arraycopy(ByteArray.shortToBytes((short) pathKey), 0, retBytes, PK_F_OFFSET, PK_F_LENGTH);
+ System.arraycopy(pceId, 0, retBytes, PCE_ID_F_OFFSET, pceId.length);
return retBytes;
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.SrlgBuilder;
+import com.google.common.primitives.UnsignedBytes;
+
/**
* Parser for {@link SrlgSubobject}
*/
public static final int TYPE = 34;
- public static final int SRLG_ID_NUMBER_LENGTH = 4;
- public static final int ATTRIBUTE_LENGTH = 1;
+ private static final int SRLG_ID_NUMBER_LENGTH = 4;
+ private static final int ATTRIBUTE_LENGTH = 1;
- public static final int SRLG_ID_NUMBER_OFFSET = 0;
- public static final int ATTRIBUTE_OFFSET = SRLG_ID_NUMBER_OFFSET + SRLG_ID_NUMBER_LENGTH + 1; // added reserved
- // field of size 1
+ private static final int SRLG_ID_NUMBER_OFFSET = 0;
+ private static final int ATTRIBUTE_OFFSET = SRLG_ID_NUMBER_OFFSET + SRLG_ID_NUMBER_LENGTH;
- public static final int CONTENT_LENGTH = ATTRIBUTE_OFFSET + ATTRIBUTE_LENGTH;
+ private static final int CONTENT_LENGTH = SRLG_ID_NUMBER_LENGTH + ATTRIBUTE_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ if (buffer.length != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
builder.setMandatory(mandatory);
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof SrlgSubobject))
+ if (!(subobject.getSubobjectType() instanceof SrlgSubobject)) {
throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed SrlgSubobject.");
+ }
byte[] retBytes;
retBytes = new byte[CONTENT_LENGTH];
final SrlgSubobject specObj = (SrlgSubobject) subobject.getSubobjectType();
- ByteArray.copyWhole(ByteArray.longToBytes(specObj.getSrlgId().getValue()), retBytes, SRLG_ID_NUMBER_OFFSET);
- retBytes[ATTRIBUTE_OFFSET] = (byte) subobject.getAttribute().getIntValue();
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getSrlgId().getValue()), 4, SRLG_ID_NUMBER_LENGTH), retBytes,
+ SRLG_ID_NUMBER_OFFSET);
+ retBytes[ATTRIBUTE_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
return retBytes;
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
+import com.google.common.primitives.UnsignedBytes;
import com.google.common.primitives.UnsignedInts;
/**
public static final int TYPE = 4;
- public static final int ATTRIBUTE_LENGTH = 1;
- public static final int ROUTER_ID_NUMBER_LENGTH = 4;
- public static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+ private static final int ATTRIBUTE_LENGTH = 1;
+ private static final int ROUTER_ID_NUMBER_LENGTH = 4;
+ private static final int INTERFACE_ID_NUMBER_LENGTH = 4;
- public static final int ATTRIBUTE_OFFSET = 1;// added reserved field of size 1
- public static final int ROUTER_ID_NUMBER_OFFSET = ATTRIBUTE_OFFSET + ATTRIBUTE_LENGTH;
- public static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
+ private static final int ATTRIBUTE_OFFSET = 1;
+ private static final int ROUTER_ID_NUMBER_OFFSET = ATTRIBUTE_OFFSET + ATTRIBUTE_LENGTH;
+ private static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
- public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
+ private static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ if (buffer.length != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
INTERFACE_ID_NUMBER_LENGTH))));
builder.setSubobjectType(ubuilder.build());
builder.setMandatory(mandatory);
- builder.setAttribute(Attribute.forValue(buffer[ATTRIBUTE_OFFSET] & 0xFF));
+ builder.setAttribute(Attribute.forValue(UnsignedBytes.toInt(buffer[ATTRIBUTE_OFFSET])));
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject))
+ if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject)) {
throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed UnnumberedSubobject.");
+ }
- byte[] retBytes;
- retBytes = new byte[CONTENT_LENGTH];
+ final byte[] retBytes = new byte[CONTENT_LENGTH];
final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
- retBytes[ATTRIBUTE_OFFSET] = (byte) subobject.getAttribute().getIntValue();
- ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId()), retBytes, ROUTER_ID_NUMBER_OFFSET);
+ retBytes[ATTRIBUTE_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
+ ROUTER_ID_NUMBER_OFFSET);
System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
return retBytes;
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl.tlv;
-
-import org.opendaylight.protocol.concepts.Ipv4Util;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiersTlv}
- */
-public class LSPIdentifierIPv4TlvParser implements TlvParser, TlvSerializer {
-
- public static final int TYPE = 18;
-
- private static final int IP_F_LENGTH = 4;
- private static final int LSP_ID_F_LENGTH = 2;
- private static final int TUNNEL_ID_F_LENGTH = 2;
- private static final int EX_TUNNEL_ID_F_LENGTH = 4;
-
- @Override
- public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
- int position = 0;
- if (valueBytes == null || valueBytes.length == 0)
- throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-
- final AddressFamily afi = new Ipv4Builder().setIpv4TunnelSenderAddress(
- Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP_F_LENGTH))).setIpv4ExtendedTunnelId(
- new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position += IP_F_LENGTH,
- EX_TUNNEL_ID_F_LENGTH)))).build();
-
- return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(
- new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position += EX_TUNNEL_ID_F_LENGTH, LSP_ID_F_LENGTH)))).setTunnelId(
- new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position += LSP_ID_F_LENGTH, TUNNEL_ID_F_LENGTH)))).build();
- }
-
- @Override
- public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
- throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
- final LspIdentifiersTlv lsp = (LspIdentifiersTlv) tlv;
- final AddressFamily afi = lsp.getAddressFamily();
- if (afi.getClass().equals(Ipv4.class)) {
- final Ipv4 ipv4 = (Ipv4) afi;
- // buffer.writeBytes(ipv4.getIpv4TunnelSenderAddress().getValue().getBytes());
- // buffer.writeBytes(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6,
- // LSP_ID_F_LENGTH));
- // buffer.writeBytes(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2,
- // TUNNEL_ID_F_LENGTH));
- // buffer.writeBytes(ipv4.getIpv4TunnelSenderAddress().getValue().getBytes());
- } else {
- final Ipv6 ipv6 = (Ipv6) afi;
- // buffer.writeBytes(ipv6.getIpv6TunnelSenderAddress().getValue().getBytes());
- // buffer.writeBytes(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6,
- // LSP_ID_F_LENGTH));
- // buffer.writeBytes(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2,
- // TUNNEL_ID_F_LENGTH));
- // buffer.writeBytes(ipv6.getIpv6TunnelSenderAddress().getValue().getBytes());
- }
- // FIXME finish
- return null;
- }
-
- @Override
- public int getType() {
- return TYPE;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl.tlv;
-
-import org.opendaylight.protocol.concepts.Ipv6Util;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiersTlv}
- */
-public class LSPIdentifierIPv6TlvParser implements TlvParser {
-
- public static final int TYPE = 19;
-
- private static final int IP_F_LENGTH = 16;
- private static final int LSP_ID_F_LENGTH = 2;
- private static final int TUNNEL_ID_F_LENGTH = 2;
- private static final int EX_TUNNEL_ID_F_LENGTH = 16;
-
- @Override
- public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
- int position = 0;
- if (valueBytes == null || valueBytes.length == 0)
- throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-
- final AddressFamily afi = new Ipv6Builder().setIpv6TunnelSenderAddress(
- Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP_F_LENGTH))).setIpv6ExtendedTunnelId(
- new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position += IP_F_LENGTH,
- EX_TUNNEL_ID_F_LENGTH)))).build();
-
- return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(
- new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position += EX_TUNNEL_ID_F_LENGTH, LSP_ID_F_LENGTH)))).setTunnelId(
- new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position += LSP_ID_F_LENGTH, TUNNEL_ID_F_LENGTH)))).build();
- }
-
- public int getType() {
- return TYPE;
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.impl.tlv;
+
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
+
+/**
+ * Parser for {@link LspIdentifiersTlv}
+ */
+public class LSPIdentifierTlvParser implements TlvParser, TlvSerializer {
+
+ public static final int TYPE = 18;
+
+ public static final int TYPE_6 = 19;
+
+ private static final int IP6_F_LENGTH = 16;
+ private static final int EX_TUNNEL_ID6_F_LENGTH = 16;
+ private static final int IP4_F_LENGTH = 4;
+ private static final int EX_TUNNEL_ID4_F_LENGTH = 4;
+
+ private static final int LSP_ID_F_LENGTH = 2;
+ private static final int TUNNEL_ID_F_LENGTH = 2;
+
+ private static final int V4_LENGTH = 12;
+ private static final int V6_LENGTH = 36;
+
+ @Override
+ public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
+ int position = 0;
+ if (valueBytes == null || valueBytes.length == 0) {
+ throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+ }
+ AddressFamily afi = null;
+ LspId lspId = null;
+ TunnelId tunnelId = null;
+ if (valueBytes.length == V4_LENGTH) {
+ final Ipv4Builder builder = new Ipv4Builder();
+ builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP4_F_LENGTH)));
+ position += IP4_F_LENGTH;
+ lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
+ position += LSP_ID_F_LENGTH;
+ tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
+ position += TUNNEL_ID_F_LENGTH;
+ builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position,
+ EX_TUNNEL_ID4_F_LENGTH))));
+ afi = builder.build();
+ position += EX_TUNNEL_ID4_F_LENGTH;
+ } else if (valueBytes.length == V6_LENGTH) {
+ final Ipv6Builder builder = new Ipv6Builder();
+ builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP6_F_LENGTH)));
+ position += IP6_F_LENGTH;
+ lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
+ position += LSP_ID_F_LENGTH;
+ tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
+ position += TUNNEL_ID_F_LENGTH;
+ builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position,
+ EX_TUNNEL_ID6_F_LENGTH))));
+ afi = builder.build();
+ position += EX_TUNNEL_ID6_F_LENGTH;
+ } else {
+ throw new IllegalArgumentException("Length " + valueBytes.length + " does not match LSP Identifiers tlv lengths.");
+ }
+
+ return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
+ }
+
+ @Override
+ public byte[] serializeTlv(final Tlv tlv) {
+ if (tlv == null) {
+ throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
+ }
+ final LspIdentifiersTlv lsp = (LspIdentifiersTlv) tlv;
+ final AddressFamily afi = lsp.getAddressFamily();
+ int offset = 0;
+ if (afi.getImplementedInterface().equals(Ipv4.class)) {
+ final byte[] bytes = new byte[V4_LENGTH];
+ final Ipv4 ipv4 = (Ipv4) afi;
+ ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelSenderAddress()), bytes, offset);
+ offset += IP4_F_LENGTH;
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+ offset += LSP_ID_F_LENGTH;
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+ offset += TUNNEL_ID_F_LENGTH;
+ ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4ExtendedTunnelId()), bytes, offset);
+ return bytes;
+ } else {
+ final byte[] bytes = new byte[V6_LENGTH];
+ final Ipv6 ipv6 = (Ipv6) afi;
+ ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelSenderAddress()), bytes, offset);
+ offset += IP6_F_LENGTH;
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+ offset += LSP_ID_F_LENGTH;
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+ offset += TUNNEL_ID_F_LENGTH;
+ ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6ExtendedTunnelId()), bytes, offset);
+ return bytes;
+ }
+ }
+
+ @Override
+ public int getType() {
+ return TYPE;
+ }
+
+ public int getType6() {
+ return TYPE_6;
+ }
+}
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("LspDbVersionTlv is mandatory.");
+ }
final LspDbVersionTlv lsp = (LspDbVersionTlv) tlv;
return ByteArray.subByte(lsp.getVersion().toByteArray(), 0, DBV_F_LENGTH);
}
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymblicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymbolicPathNameBuilder;
/**
* Parser for {@link SymbolicPathNameTlv}
@Override
public SymbolicPathNameTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
- return new SymblicPathNameBuilder().setPathName(buffer).build();
+ return new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(buffer)).build();
}
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
+ }
final SymbolicPathNameTlv spn = (SymbolicPathNameTlv) tlv;
- return spn.getPathName();
+ return spn.getPathName().getValue();
}
@Override
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("LspErrorCodeTlv is mandatory.");
+ }
final LspErrorCodeTlv lsp = (LspErrorCodeTlv) tlv;
- return ByteArray.subByte(ByteArray.longToBytes(lsp.getErrorCode()), 0, UPDATE_ERR_CODE_LENGTH);
+ return ByteArray.subByte(ByteArray.longToBytes(lsp.getErrorCode()), UPDATE_ERR_CODE_LENGTH, UPDATE_ERR_CODE_LENGTH);
}
@Override
public static final int TYPE = 1;
- public static final int FLAGS_F_LENGTH = 4;
+ private static final int FLAGS_F_LENGTH = 4;
- /*
- * flags offsets inside flags field in bits
- */
- public static final int PCE_UNAVAILABLE = 31;
- public static final int UNKNOWN_DEST = 30;
- public static final int UNKNOWN_SRC = 29;
-
- /*
- * flags offsets of flags added by GCO extension
- */
- public static final int NO_GCO_SOLUTION = 25;
- public static final int NO_GCO_MIGRATION_PATH = 26;
-
- /*
- * flags offsets of flags added by RFC 6006
- */
- public static final int REACHABLITY_PROBLEM = 24;
+ private static final int REACHABLITY_PROBLEM = 24;
+ private static final int NO_GCO_SOLUTION = 25;
+ private static final int NO_GCO_MIGRATION_PATH = 26;
+ private static final int PATH_KEY = 27;
+ private static final int CHAIN_UNAVAILABLE = 28;
+ private static final int UNKNOWN_SRC = 29;
+ private static final int UNKNOWN_DEST = 30;
+ private static final int PCE_UNAVAILABLE = 31;
@Override
public NoPathVectorTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
- if (valueBytes == null || valueBytes.length == 0)
+ if (valueBytes == null || valueBytes.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-
- if (valueBytes.length != FLAGS_F_LENGTH)
+ }
+ if (valueBytes.length != FLAGS_F_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >="
+ FLAGS_F_LENGTH + ".");
-
+ }
final BitSet flags = ByteArray.bytesToBitSet(valueBytes);
-
return new NoPathVectorBuilder().setFlags(
- new Flags(false, flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), false, flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
+ new Flags(flags.get(CHAIN_UNAVAILABLE), flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), flags.get(PATH_KEY), flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
}
@Override
public byte[] serializeTlv(final Tlv tlvs) {
- if (tlvs == null)
+ if (tlvs == null) {
throw new IllegalArgumentException("NoPathVectorTlv is mandatory.");
+ }
final NoPathVectorTlv tlv = (NoPathVectorTlv) tlvs;
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-
- flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
- flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
- flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
+ flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
flags.set(NO_GCO_SOLUTION, tlv.getFlags().isNoGcoSolution());
flags.set(NO_GCO_MIGRATION_PATH, tlv.getFlags().isNoGcoMigration());
- flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
-
+ flags.set(PATH_KEY, tlv.getFlags().isPathKey());
+ flags.set(CHAIN_UNAVAILABLE, tlv.getFlags().isChainUnavailable());
+ flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
+ flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
+ flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
}
@Override
public OfListTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
- if (valueBytes == null || valueBytes.length == 0)
+ if (valueBytes == null || valueBytes.length == 0) {
throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
- if (valueBytes.length % OF_CODE_ELEMENT_LENGTH != 0)
+ }
+ if (valueBytes.length % OF_CODE_ELEMENT_LENGTH != 0) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + ".");
-
+ }
final List<OfId> ofCodes = Lists.newArrayList();
for (int i = 0; i < valueBytes.length; i += OF_CODE_ELEMENT_LENGTH) {
try {
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("OFListTlv is mandatory.");
+ }
final OfListTlv oft = (OfListTlv) tlv;
final List<OfId> ofCodes = oft.getCodes();
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("OrderTlv is mandatory.");
+ }
final OrderTlv otlv = (OrderTlv) tlv;
-
- // final byte[] bytes = new byte[];
- // FIXME: finish
-
- final byte[] delete = ByteArray.subByte(ByteArray.longToBytes(otlv.getDelete()), 4, ORDR_DEL_LENGTH);
- // buffer.writeBytes(delete);
- final byte[] setup = ByteArray.subByte(ByteArray.longToBytes(otlv.getSetup()), 4, ORDR_SETUP_LENGTH);
- // buffer.writeBytes(setup);
-
- return new byte[5];
+ final byte[] bytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH];
+ int offset = 0;
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getDelete()), 4, ORDR_DEL_LENGTH), bytes, offset);
+ offset += ORDR_DEL_LENGTH;
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getSetup()), 4, ORDR_SETUP_LENGTH), bytes, offset);
+ return bytes;
}
@Override
-/**
- *
+/*
+ * Copyright (c) 2013 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.pcep.impl.tlv;
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("OverloadedTlv is mandatory.");
+ }
final OverloadDurationTlv odt = (OverloadDurationTlv) tlv;
- return ByteArray.subByte(ByteArray.longToBytes(odt.getDuration()), 4, OVERLOADED_DURATION_LENGTH);
+ return ByteArray.subByte(ByteArray.longToBytes(odt.getDuration()), OVERLOADED_DURATION_LENGTH, OVERLOADED_DURATION_LENGTH);
}
@Override
public final class PCEStatefulCapabilityTlvParser implements TlvParser, TlvSerializer {
public static final int TYPE = 16;
- /*
- * Flags field length in Bytes
- */
- public static final int FLAGS_F_LENGTH = 4;
- /*
- * Offsets inside flags field in bits;
- */
- public static final int I_FLAG_OFFSET = 29;
- public static final int S_FLAG_OFFSET = 30;
- public static final int U_FLAG_OFFSET = 31;
+ private static final int FLAGS_F_LENGTH = 4;
+
+ private static final int I_FLAG_OFFSET = 29;
+ private static final int S_FLAG_OFFSET = 30;
+ private static final int U_FLAG_OFFSET = 31;
@Override
public StatefulCapabilityTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
- if (buffer.length < FLAGS_F_LENGTH)
+ }
+ if (buffer.length < FLAGS_F_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
+ FLAGS_F_LENGTH + ".");
+ }
final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
return new StatefulBuilder().setFlags(new Flags(flags.get(S_FLAG_OFFSET), flags.get(I_FLAG_OFFSET), flags.get(U_FLAG_OFFSET))).build();
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("StatefulCapabilityTlv is mandatory.");
+ }
final StatefulCapabilityTlv sct = (StatefulCapabilityTlv) tlv;
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.ErrorType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.Rsvp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.RsvpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.User;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.UserBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpError;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserError;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserErrorBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags;
/**
* Parser for {@link RsvpErrorSpecTlv}
*/
-public class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
+public final class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
+
+ public static final int TYPE = 21;
private static final int IP4_F_LENGTH = 4;
private static final int IP6_F_LENGTH = 16;
private static final int USER_ERROR_CLASS_NUM = 194;
private static final int USER_ERROR_CLASS_TYPE = 1;
- public static final int TYPE = 21;
-
- /*
- * flags offsets inside flags field in bits
- */
private static final int IN_PLACE_FLAG_OFFSET = 7;
private static final int NOT_GUILTY_FLAGS_OFFSET = 6;
+ private static final int V4_RSVP_LENGTH = 10;
+ private static final int V6_RSVP_LENGTH = 22;
+
@Override
public RsvpErrorSpecTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
- if (valueBytes == null || valueBytes.length == 0)
+ if (valueBytes == null || valueBytes.length == 0) {
throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+ }
- final int classNum = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 2, 1));
- final int classType = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 3, 1));
+ final int classNum = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 0, 1));
+ final int classType = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 1, 1));
ErrorType errorType = null;
- int byteOffset = 0;
+ final int byteOffset = 2;
if (classNum == RSVP_ERROR_CLASS_NUM) {
- final RsvpErrorBuilder builder = new RsvpErrorBuilder();
- if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
- builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
- byteOffset += IP4_F_LENGTH;
- } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
- builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
- byteOffset += IP6_F_LENGTH;
- }
- final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
- byteOffset += FLAGS_F_LENGTH;
-
- final short errorCode = (short) (valueBytes[byteOffset] & 0xFF);
- byteOffset += ERROR_CODE_F_LENGTH;
- final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
-
- errorType = new RsvpBuilder().setRsvpError(
- builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET))).setCode(errorCode).setValue(
- errorValue).build()).build();
+ errorType = parseRsvp(classType, ByteArray.cutBytes(valueBytes, byteOffset));
} else if (classNum == USER_ERROR_CLASS_NUM && classType == USER_ERROR_CLASS_TYPE) {
- final UserErrorBuilder error = new UserErrorBuilder();
- error.setEnterprise(new EnterpriseNumber(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, byteOffset, ENTERPRISE_F_LENGTH))));
- byteOffset += ENTERPRISE_F_LENGTH;
- error.setSubOrg(ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, SUB_ORG_F_LENGTH)));
- byteOffset += SUB_ORG_F_LENGTH;
- final int errDescrLength = UnsignedBytes.toInt(valueBytes[byteOffset]);
- byteOffset += ERR_DESCR_LENGTH_F_LENGTH;
- error.setValue(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, byteOffset, USER_VALUE_F_LENGTH)));
- byteOffset += USER_VALUE_F_LENGTH;
- error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
- byteOffset += errDescrLength;
- if (byteOffset < valueBytes.length) {
- // TODO: if we have any subobjects
- // error.setSubobjects(new SubobjectsBuilder().build());
- }
- errorType = new UserBuilder().setUserError(error.build()).build();
+ errorType = parseUserError(ByteArray.cutBytes(valueBytes, byteOffset));
}
-
return new RsvpErrorSpecBuilder().setErrorType(errorType).build();
}
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("RSVPErrorSpecTlv is mandatory.");
+ }
final RsvpErrorSpecTlv rsvp = (RsvpErrorSpecTlv) tlv;
- if (rsvp.getErrorType().getClass().equals(Rsvp.class)) {
+ if (rsvp.getErrorType().getImplementedInterface().equals(Rsvp.class)) {
final Rsvp r = (Rsvp) rsvp.getErrorType();
- final RsvpError e = r.getRsvpError();
- final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
- flags.set(IN_PLACE_FLAG_OFFSET, e.getFlags().isInPlace());
- flags.set(NOT_GUILTY_FLAGS_OFFSET, e.getFlags().isNotGuilty());
- final IpAddress node = e.getNode();
- if (node.getIpv4Address() != null) {
+ return serializeRsvp(r.getRsvpError());
+ } else {
+ final User u = (User) rsvp.getErrorType();
+ return serializerUserError(u.getUserError());
+ }
+ }
- }
+ private User parseUserError(final byte[] valueBytes) {
+ final UserErrorBuilder error = new UserErrorBuilder();
+ int byteOffset = 0;
+ error.setEnterprise(new EnterpriseNumber(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, byteOffset, ENTERPRISE_F_LENGTH))));
+ byteOffset += ENTERPRISE_F_LENGTH;
+ error.setSubOrg((short) UnsignedBytes.toInt(valueBytes[byteOffset]));
+ byteOffset += SUB_ORG_F_LENGTH;
+ final int errDescrLength = UnsignedBytes.toInt(valueBytes[byteOffset]);
+ byteOffset += ERR_DESCR_LENGTH_F_LENGTH;
+ error.setValue(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, byteOffset, USER_VALUE_F_LENGTH)));
+ byteOffset += USER_VALUE_F_LENGTH;
+ error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
+ byteOffset += errDescrLength;
+ // TODO: if we have any subobjects
+ return new UserBuilder().setUserError(error.build()).build();
+ }
- } else {
+ private byte[] serializerUserError(final UserError ue) {
+ final byte[] enterprise = ByteArray.subByte(ByteArray.longToBytes(ue.getEnterprise().getValue()), 4, ENTERPRISE_F_LENGTH);
+ final byte suborg = UnsignedBytes.checkedCast(ue.getSubOrg());
+ final byte[] value = ByteArray.subByte(ByteArray.intToBytes(ue.getValue()), 2, USER_VALUE_F_LENGTH);
+ final byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
+ final byte descLen = UnsignedBytes.checkedCast(desc.length);
+ // TODO: if we have any subobjects
+ final byte[] bytes = new byte[2 + ENTERPRISE_F_LENGTH + SUB_ORG_F_LENGTH + USER_VALUE_F_LENGTH + ERR_DESCR_LENGTH_F_LENGTH
+ + desc.length];
+ bytes[0] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_NUM);
+ bytes[1] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_TYPE);
+ int offset = 2;
+ ByteArray.copyWhole(enterprise, bytes, offset);
+ offset += ENTERPRISE_F_LENGTH;
+ bytes[offset] = suborg;
+ offset += SUB_ORG_F_LENGTH;
+ bytes[offset] = descLen;
+ offset += ERR_DESCR_LENGTH_F_LENGTH;
+ ByteArray.copyWhole(value, bytes, offset);
+ offset += USER_VALUE_F_LENGTH;
+ ByteArray.copyWhole(desc, bytes, offset);
+ return bytes;
+ }
+ private Rsvp parseRsvp(final int classType, final byte[] valueBytes) {
+ int byteOffset = 0;
+ final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+ if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
+ builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
+ byteOffset += IP4_F_LENGTH;
+ } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
+ builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
+ byteOffset += IP6_F_LENGTH;
+ }
+ final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
+ byteOffset += FLAGS_F_LENGTH;
+ builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET)));
+ final short errorCode = (short) (valueBytes[byteOffset] & Util.BYTE_MAX_VALUE_BYTES);
+ byteOffset += ERROR_CODE_F_LENGTH;
+ builder.setCode(errorCode);
+ final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
+ builder.setValue(errorValue);
+ return new RsvpBuilder().setRsvpError(builder.build()).build();
+ }
+
+ private byte[] serializeRsvp(final RsvpError rsvp) {
+ final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
+ flags.set(IN_PLACE_FLAG_OFFSET, rsvp.getFlags().isInPlace());
+ flags.set(NOT_GUILTY_FLAGS_OFFSET, rsvp.getFlags().isNotGuilty());
+ int offset = 0;
+ final IpAddress node = rsvp.getNode();
+ byte[] bytes;
+ if (node.getIpv4Address() != null) {
+ bytes = new byte[V4_RSVP_LENGTH];
+ bytes[0] = RSVP_ERROR_CLASS_NUM;
+ bytes[1] = RSVP_IPV4_ERROR_CLASS_TYPE;
+ offset += 2;
+ ByteArray.copyWhole(Ipv4Util.bytesForAddress(node.getIpv4Address()), bytes, offset);
+ offset += IP4_F_LENGTH;
+ } else {
+ bytes = new byte[V6_RSVP_LENGTH];
+ bytes[0] = RSVP_ERROR_CLASS_NUM;
+ bytes[1] = RSVP_IPV6_ERROR_CLASS_TYPE;
+ offset += 2;
+ ByteArray.copyWhole(Ipv6Util.bytesForAddress(node.getIpv6Address()), bytes, offset);
+ offset += IP6_F_LENGTH;
}
- // TODO: finish
- return null;
+ bytes[offset] = ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH)[0];
+ offset += FLAGS_F_LENGTH;
+ bytes[offset] = UnsignedBytes.checkedCast(rsvp.getCode());
+ offset += ERROR_CODE_F_LENGTH;
+ final byte[] value = ByteArray.subByte(ByteArray.intToBytes(rsvp.getValue().intValue()), 2, ERROR_VALUE_F_LENGTH);
+ ByteArray.copyWhole(value, bytes, offset);
+ return bytes;
}
@Override
*/
public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
- private static final int REQ_ID_LENGTH = 4;
-
public static final int TYPE = 3;
+ private static final int REQ_ID_LENGTH = 4;
+
@Override
public ReqMissingTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
return new ReqMissingBuilder().setRequestId(new RequestId(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, REQ_ID_LENGTH)))).build();
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null)
+ if (tlv == null) {
throw new IllegalArgumentException("ReqMissingTlv is mandatory.");
+ }
final ReqMissingTlv req = (ReqMissingTlv) tlv;
- return ByteArray.subByte(ByteArray.longToBytes(req.getRequestId().getValue()), 4, REQ_ID_LENGTH);
+ return ByteArray.subByte(ByteArray.longToBytes(req.getRequestId().getValue()), REQ_ID_LENGTH, REQ_ID_LENGTH);
}
@Override
--- /dev/null
+org.opendaylight.protocol.pcep.impl.Activator
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabelBuilder;
+
+public class LabelSubobjectParserTest {
+
+ private static final byte[] generalizedLabelBytes = { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+
+ private static final byte[] wavebandLabelBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x00, (byte) 0x00,
+ (byte) 0x99, (byte) 0x99, (byte) 0x00, (byte) 0x00, (byte) 0x11, (byte) 0x11 };
+
+ @Test
+ public void testGeneralizedLabel() throws PCEPDeserializerException {
+ final GeneralizedLabelParser parser = new GeneralizedLabelParser();
+ final GeneralizedLabelBuilder builder = new GeneralizedLabelBuilder();
+ builder.setGeneralizedLabel(generalizedLabelBytes);
+ assertEquals(builder.build(), parser.parseLabel(generalizedLabelBytes));
+ assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(builder.build()));
+ }
+
+ @Test
+ public void testWavebandLabel() throws PCEPDeserializerException {
+ final WavebandSwitchingLabelParser parser = new WavebandSwitchingLabelParser();
+ final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
+ builder.setWavebandId(0x1234L);
+ builder.setStartLabel(0x9999L);
+ builder.setEndLabel(0x1111L);
+ assertEquals(builder.build(), parser.parseLabel(wavebandLabelBytes));
+ assertArrayEquals(wavebandLabelBytes, parser.serializeLabel(builder.build()));
+ }
+
+ @Test
+ public void testTypeOneLabel() throws PCEPDeserializerException {
+ final Type1LabelParser parser = new Type1LabelParser();
+ final Type1LabelBuilder builder = new Type1LabelBuilder();
+ builder.setType1Label(0x120025ffL);
+ assertEquals(builder.build(), parser.parseLabel(generalizedLabelBytes));
+ assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(builder.build()));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROExplicitExclusionRouteSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+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.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.ExrsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
+
+import com.google.common.collect.Lists;
+
+public class PCEPEROSubobjectParserTest {
+ private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
+ private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
+ private static final byte[] asNumberBytes = { (byte) 0x00, (byte) 0x64 };
+ private static final byte[] unnumberedBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+ private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
+ private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+ private static final byte[] labelBytes = { (byte) 0x80, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+ private static final byte[] exrsBytes = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 };
+
+ @Test
+ public void testEROIp4PrefixSubobject() throws PCEPDeserializerException {
+ final EROIpPrefixSubobjectParser parser = new EROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setLoose(true);
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
+ assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes, true));
+ assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testEROIp6PrefixSubobject() throws PCEPDeserializerException {
+ final EROIpPrefixSubobjectParser parser = new EROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
+ subs.setLoose(false);
+ assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes, false));
+ assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testEROAsNumberSubobject() throws PCEPDeserializerException {
+ final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setLoose(true);
+ subs.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
+ assertEquals(subs.build(), parser.parseSubobject(asNumberBytes, true));
+ assertArrayEquals(asNumberBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testEROUnnumberedSubobject() throws PCEPDeserializerException {
+ final EROUnnumberedInterfaceSubobjectParser parser = new EROUnnumberedInterfaceSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setLoose(true);
+ subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
+ assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes, true));
+ assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testEROPathKey32Subobject() throws PCEPDeserializerException {
+ final EROPathKeySubobjectParser parser = new EROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setLoose(true);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes, true));
+ assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testEROPathKey128Subobject() throws PCEPDeserializerException {
+ final EROPathKeySubobjectParser parser = new EROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setLoose(true);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+ (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes, true));
+ assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testEROLabelSubobject() throws Exception {
+ final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(PCEPExtensionProviderContextImpl.create().getLabelHandlerRegistry());
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setLoose(true);
+ subs.setSubobjectType(new LabelBuilder().setUniDirectional(true).setLabelType(
+ new GeneralizedLabelBuilder().setGeneralizedLabel(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(labelBytes, true));
+ assertArrayEquals(labelBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testEROEXRSSubobject() throws Exception {
+ final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser(PCEPExtensionProviderContextImpl.create().getXROSubobjectHandlerRegistry());
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setLoose(true);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs> list = Lists.newArrayList();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder();
+ builder.setMandatory(true);
+ builder.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
+ list.add(builder.build());
+ subs.setSubobjectType(new ExrsBuilder().setExrs(list).build());
+ assertEquals(subs.build(), parser.parseSubobject(exrsBytes, true));
+ // assertArrayEquals(exrsBytes, parser.serializeSubobject(subs.build()));
+ }
+}
*/
package org.opendaylight.protocol.pcep.impl;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.PCEPDocumentedException;
+import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.ClassTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.LspaBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.OfBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.SrpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.reported.route.BandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.GcBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
+
+import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
-/**
- * Used resources<br/>
- * <br/>
- * PCEPOpenObject3.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * keepAlive: 30<br/>
- * deadTimer: 120<br/>
- * sessionId: 1<br/>
- * tlvs:NO<br/>
- * <br/>
- * PCEPBandwidthObject1LowerBounds.bin<br/>
- * objClass: 5 <br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Bandwidth: 0<br/>
- * <br/>
- * PCEPBandwidthObject2UpperBounds.bin<br/>
- * objClass: 5 <br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Bandwidth: 0xFFFFFFFF<br/>
- * <br/>
- * PCEPEndPointsObject1IPv4.bin<br/>
- * objClass: 4 <br/>
- * objType: 1<br/>
- * objLength: 12<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * src IP: 0xA2F5110E <br/>
- * dest IP: 0xFFFFFFFF <br/>
- * <br/>
- * PCEPEndPointsObject2IPv6.bin<br/>
- * objClass: 4 <br/>
- * objType: 2<br/>
- * objLength: 36<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF<br/>
- * dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000 <br/>
- * <br/>
- * PCEPErrorObject1.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 1<br/>
- * Error-value: 1<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPErrorObject2Invalid.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 3<br/>
- * Error-value: 0<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPErrorObject3.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 2<br/>
- * Error-value: 0<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPLspaObject1LowerBounds.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0x00000000L<br/>
- * Include-any: 0x00000000L<br/>
- * Include-all: 0x00000000L<br/>
- * Setup Prio: 0x00<br/>
- * Holding Prio: 0x00<br/>
- * Flags: - L : false<br/>
- * <br/>
- * PCEPLspaObject2UpperBounds.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0xFFFFFFFFL<br/>
- * Include-any: 0xFFFFFFFFL<br/>
- * Include-all: 0xFFFFFFFFL<br/>
- * Setup Prio: 0xFF<br/>
- * Holding Prio: 0xFF<br/>
- * Flags: - L : true<br/>
- * <br/>
- * PCEPLspaObject3RandVals.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0x20A1FEE3L<br/>
- * Include-any: 0x1A025CC7L<br/>
- * Include-all: 0x2BB66532L<br/>
- * Setup Prio: 0x03<br/>
- * Holding Prio: 0x02<br/>
- * Flags: - L : true<br/>
- * <br/>
- * NoPathObject1WithTLV.bin<br/>
- * objClass: 3 (RP)<br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Nature of Issue: 2<br/>
- * No-Path flags:<br/>
- * - C: true<br/>
- * <br/>
- * tlvs:<br/>
- * -- NO-PATH-VECTOR<br/>
- * - flags (0x4000):<br/>
- * - PCE currently unavailable: false<br/>
- * - unknown destination: true<br/>
- * - unknown source: false<br/>
- *
- * <br/>
- * NoPathObject2WithoutTLV.bin<br/>
- * objClass: 3 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: true<br/>
- * <br/>
- * Nature of Issue: 16<br/>
- * No-Path flags:<br/>
- * - C: false<br/>
- * <br/>
- * tlvs:NO<br/>
- * <br/>
- * PCEPNotificationObject1WithTlv.bin <br/>
- * objClass: 12<br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * NT: 1<br/>
- * NV: 1<br/>
- * Tlvs:<br/>
- * - OverloaderDuration(0xFF0000A2L)<br/>
- * <br/>
- * PCEPNotificationObject2WithoutTlv.bin <br/>
- * objClass: 12<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * NT: 0xFF<br/>
- * NV: 0xFF<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPOpenObject1.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 28<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * keepAlive: 30<br/>
- * deadTimer: 120<br/>
- * sessionId: 1<br/>
- * tlvs:<br/>
- * - PCEPStatefulCapability<br/>
- * - LSPStateDBVersionTlv<br/>
- * - NodeIdentifierTlv<br/>
- * <br/>
- * PCEPOpenObject2UpperBoundsNoTlv.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 34<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * keepAlive: 0xFF<br/>
- * deadTimer: 0xFF<br/>
- * sessionId: 0xFF<br/>
- * tlvs: NO<br/>
- * <br/>
- * PCEPRPObject1.bin<br/>
- * objClass: 2 (RP)<br/>
- * objType: 1<br/>
- * objLength: 12<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * RP flags:<br/>
- * - loose/strict: true<br/>
- * - Bi-directional: false<br/>
- * - Reoptimization: false<br/>
- * - Priority: 5<br/>
- * Request ID: 0xDEADBEEF<br/>
- * tlvs: NO<br/>
- * <br/>
- * PCEPSvecObject1_10ReqIDs.bin <br/>
- * objClass: 11<br/>
- * objType: 1<br/>
- * objLength: 48<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: false<br/>
- * <br/>
- * Flags:<br/>
- * - Link diverse: true<br/>
- * - Node diverse: false<br/>
- * - SRLG diverse: true<br/>
- * Reques-ID-numbers:<br/>
- * #1 - 0xFFFFFFFFL<br/>
- * #2 - 0x00000000L<br/>
- * #3 - 0x01234567L<br/>
- * #4 - 0x89ABCDEFL<br/>
- * #5 - 0xFEDCBA98L<br/>
- * #6 - 0x76543210L<br/>
- * #7 - 0x15825266L<br/>
- * #8 - 0x48120BBEL<br/>
- * #9 - 0x25FB7E52L<br/>
- * #10 - 0xB2F2546BL<br/>
- * <br/>
- * PCEPSvecObject2.bin <br/>
- * objClass: 11<br/>
- * objType: 1<br/>
- * objLength: 08<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Flags:<br/>
- * - Link diverse: false<br/>
- * - Node diverse: false<br/>
- * - SRLG diverse: false<br/>
- * Reques-ID-numbers:<br/>
- * #1 - 0x000000FFL<br/>
- * PCEPExcludeRouteObject.1.bin <br/>
- * objClass: 17 <br/>
- * objType: 1 <br/>
- * objLength: 20 <br/>
- * version: 1 <br/>
- * Flags: <br/>
- * - fail: true <br/>
- * Subobjects: <br/>
- * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node) <br/>
- * - XROASnumber(0x1234) <br/>
- */
public class PCEPObjectParserTest {
- // @Mock
- // private HandlerRegistry registry;
- //
- // IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
- //
- // IPv6Address ipv6addr = new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1,
- // (byte) 192, (byte) 168,
- // 2, 1, (byte) 192, (byte) 168, 2, 1 });
- //
- // @SuppressWarnings("unchecked")
- // private static <T extends PCEPObject> void serDeserTest(final String srcFile, final T specObject) throws
- // IOException,
- // PCEPDeserializerException, PCEPDocumentedException {
- // final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
- // final T deserSpecObj = (T) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
- // final byte[] serSpecObj = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObject));
- //
- // assertEquals(specObject, deserSpecObj);
- // assertArrayEquals(bytesFromFile, serSpecObj);
- // }
- //
- // /**
- // * Standard serialization test<br/>
- // * Used resources:<br/>
- // * - PCEPOpenObject1.bin<br/>
- // *
- // * @throws PCEPDeserializerException
- // * @throws IOException
- // * @throws PCEPDocumentedException
- // */
+ private TlvHandlerRegistry tlvRegistry;
+
+ @Before
+ public void setUp() throws Exception {
+ this.tlvRegistry = PCEPExtensionProviderContextImpl.create().getTlvHandlerRegistry();
+ }
+
// @Test
// @Ignore
// // FIXME: temporary
// // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
// // }
// //
- // // @Test
- // // public void testCloseObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
- // // serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG));
- // // }
- //
- // @Test
- // @Ignore
- // // FIXME BUG-89
- // public void testLoadBalancingObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException
- // {
- // serDeserTest("src/test/resources/PCEPLoadBalancingObject1.bin", new PCEPLoadBalancingObject(0xF1, new
- // Bandwidth(new byte[] {
- // (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }), true));
- // }
+
+ @Test
+ public void testCloseObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry);
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin");
+
+ final CCloseBuilder builder = new CCloseBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setReason((short) 5);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testLoadBalancingObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser(this.tlvRegistry);
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin");
+
+ final LoadBalancingBuilder builder = new LoadBalancingBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
+ builder.setMinBandwidth(new Float32(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
//
// @Test
// public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// assertArrayEquals(bytesFromFile, bytesActual);
// }
//
- // /**
- // * Test for upper/lower bounds (Serialization/Deserialization)<br/>
- // * Used resources:<br/>
- // * - PCEPBandwidthObject2UpperBounds.bin<br/>
- // * - PCEPBandwidthObject1LowerBounds.bin<br/>
- // *
- // * @throws IOException
- // * @throws PCEPDeserializerException
- // * @throws PCEPDocumentedException
- // */
- // @Test
- // @Ignore
- // // FIXME BUG-89
- // public void testBandwidthObjectBounds() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
- // serDeserTest("src/test/resources/PCEPBandwidthObject1LowerBounds.bin",
- // new PCEPRequestedPathBandwidthObject(new Bandwidth(new byte[] { 0, 0, 0, 0 }), true, true));
- // }
- //
- // /**
- // * Test for upper/lower bounds of IPv4 EndPoints (Serialization/Deserialization)<br/>
- // * Used resources:<br/>
- // * - PCEPEndPointsObject1IPv4.bin<br/>
- // *
- // * @throws IOException
- // * @throws PCEPDeserializerException
- // * @throws PCEPDocumentedException
- // */
- // @Test
- // public void testEndPointsObjectSerDeserIPv4() throws IOException, PCEPDeserializerException,
- // PCEPDocumentedException {
- // final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
- // final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
- // serDeserTest("src/test/resources/PCEPEndPointsObject1IPv4.bin",
- // new PCEPEndPointsObject<IPv4Address>(new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes)));
- // }
- //
- // /**
- // * Test for upper/lower bounds of IPv6 EndPoints (Serialization/Deserialization)<br/>
- // * Used resources:<br/>
- // * - PCEPEndPointsObject2IPv6.bin<br/>
- // *
- // * @throws IOException
- // * @throws PCEPDeserializerException
- // * @throws PCEPDocumentedException
- // */
- // @Test
- // public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException,
- // PCEPDocumentedException {
- // final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte)
- // 0xA1,
- // (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte)
- // 0x00, };
- // final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte)
- // 0xFF, (byte) 0xFF,
- // (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
- //
- // serDeserTest("src/test/resources/PCEPEndPointsObject2IPv6.bin",
- // new PCEPEndPointsObject<IPv6Address>(new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes)));
- // }
+
+ @Test
+ public void testBandwidthObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser(this.tlvRegistry);
+ byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin");
+
+ final BandwidthBuilder builder = new BandwidthBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setBandwidth(new Float32(result));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+ result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin");
+
+ builder.setBandwidth(new Float32(result));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
+ final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+
+ final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin");
+
+ final EndpointsBuilder builder = new EndpointsBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setAddressFamily(new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
+ Ipv4Util.addressForBytes(destIPBytes)).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
+ (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
+ final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+
+ final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin");
+
+ final EndpointsBuilder builder = new EndpointsBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setAddressFamily(new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
+ Ipv6Util.addressForBytes(destIPBytes)).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
//
// /**
// * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
// PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0);
// }
//
- // /**
- // * Test for upper/lower bounds of PCEPLspaObject (Serialization/Deserialization)<br/>
- // * Used resources:<br/>
- // * - PCEPLspaObject1LowerBounds.bin<br/>
- // * - PCEPLspaObject2UpperBounds.bin<br/>
- // * - PCEPLspaObject3RandVals.bin<br/>
- // *
- // * @throws IOException
- // * @throws PCEPDeserializerException
- // * @throws PCEPDocumentedException
- // */
- // @Test
- // public void testLspaObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
- // serDeserTest("src/test/resources/PCEPLspaObject2UpperBounds.bin",
- // new PCEPLspaObject(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, (short) 0xFF, (short) 0xFF, false, true, true, true));
- // serDeserTest("src/test/resources/PCEPLspaObject1LowerBounds.bin",
- // new PCEPLspaObject(0x00000000L, 0x00000000L, 0x00000000L, (short) 0x00, (short) 0x00, false, false, true, true));
- // serDeserTest("src/test/resources/PCEPLspaObject3RandVals.bin",
- // new PCEPLspaObject(0x20A1FEE3L, 0x1A025CC7L, 0x2BB66532L, (short) 0x03, (short) 0x02, false, true, true, true));
- // }
- //
- // @Test
- // public void testMetricObjectSerDeserBounds() throws IOException, PCEPDeserializerException,
- // PCEPDocumentedException {
- // final byte[] bytesFromFileUB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
- // final byte[] bytesFromFileLB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
- //
- // final PCEPMetricObject metricObjectLB = (PCEPMetricObject)
- // PCEPObjectFactory.parseObjects(bytesFromFileLB).get(0);
- // final PCEPMetricObject metricObjectUB = (PCEPMetricObject)
- // PCEPObjectFactory.parseObjects(bytesFromFileUB).get(0);
- //
- // assertEquals(new PCEPMetricObject(false, false, new IGPMetric(0), true, true), metricObjectLB);
- // assertEquals(new PCEPMetricObject(false, true, new TEMetric(4026531840L), true, true), metricObjectUB);
- //
- // final byte[] bytesActualLB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectLB));
- // final byte[] bytesActualUB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectUB));
- // assertArrayEquals(bytesFromFileLB, bytesActualLB);
- // assertArrayEquals(bytesFromFileUB, bytesActualUB);
- // }
- //
- // /**
- // * Standard deserialization test + specific test without tlv<br/>
- // * Used resources:<br/>
- // * - NoPathObject1WithTLV.bin<br/>
- // * - NoPathObject2WithoutTLV.bin<br/>
- // *
- // * @throws PCEPDeserializerException
- // * @throws IOException
- // * @throws PCEPDocumentedException
- // */
+
+ @Test
+ public void testLspaObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry);
+ byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin");
+
+ final LspaBuilder builder = new LspaBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setExcludeAny(new AttributeFilter(0L));
+ builder.setIncludeAny(new AttributeFilter(0L));
+ builder.setIncludeAll(new AttributeFilter(0L));
+ builder.setHoldPriority((short) 0);
+ builder.setSetupPriority((short) 0);
+ builder.setLocalProtectionDesired(false);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+ result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin");
+
+ builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
+ builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
+ builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
+ builder.setHoldPriority((short) 0xFF);
+ builder.setSetupPriority((short) 0xFF);
+ builder.setLocalProtectionDesired(true);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+ result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin");
+
+ builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L));
+ builder.setIncludeAny(new AttributeFilter(0x1A025CC7L));
+ builder.setIncludeAll(new AttributeFilter(0x2BB66532L));
+ builder.setHoldPriority((short) 0x02);
+ builder.setSetupPriority((short) 0x03);
+ builder.setLocalProtectionDesired(true);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testMetricObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPMetricObjectParser parser = new PCEPMetricObjectParser(this.tlvRegistry);
+ byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
+
+ final MetricBuilder builder = new MetricBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setComputed(false);
+ builder.setBound(false);
+ builder.setMetricType((short) 1);
+ builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+ result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
+
+ builder.setComputed(true);
+ builder.setBound(false);
+ builder.setMetricType((short) 2);
+ builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
// @Test
- // public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException,
- // PCEPDocumentedException {
- // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
- // // tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
- // // serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs,
- // false));
+ // public void testNoPathObject() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
+ // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
+ // tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
+ // serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs, false));
// serDeserTest("src/test/resources/NoPathObject2WithoutTLV.bin", new PCEPNoPathObject((short) 0x10, false, true));
//
- // }
- //
- // /**
- // * Standard serialization test + without tlv<br/>
- // * Used resources:<br/>
- // * - NoPathObject1WithTLV.bin<br/>
- // * - NoPathObject2WithoutTLV.bin<br/>
- // *
- // * @throws PCEPDeserializerException
- // * @throws IOException
- // * @throws PCEPDocumentedException
- // */
- // @Test
- // public void testNoPathObjectSerialization() throws IOException, PCEPDeserializerException,
- // PCEPDocumentedException {
// byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject2WithoutTLV.bin");
// PCEPNoPathObject noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
// byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
// bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
// assertArrayEquals(bytesFromFile, bytesActual);
// }
+
//
// /**
// * Specific test with/without tlvs (Ser/Deser)<br/>
// // }, false, false));
// }
//
- // /**
- // * Test for upper/lower bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
- // * Used resources:<br/>
- // * - PCEPSvecObject1_10ReqIDs.bin<br/>
- // *
- // * @throws IOException
- // * @throws PCEPDeserializerException
- // * @throws PCEPDocumentedException
- // */
- // @Test
- // public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
- // final List<Long> requestIDs = new ArrayList<Long>(10);
- // requestIDs.add(0xFFFFFFFFL);
- // requestIDs.add(0x00000000L);
- // requestIDs.add(0x01234567L);
- // requestIDs.add(0x89ABCDEFL);
- // requestIDs.add(0xFEDCBA98L);
- // requestIDs.add(0x76543210L);
- // requestIDs.add(0x15825266L);
- // requestIDs.add(0x48120BBEL);
- // requestIDs.add(0x25FB7E52L);
- // requestIDs.add(0xB2F2546BL);
- //
- // serDeserTest("src/test/resources/PCEPSvecObject1_10ReqIDs.bin",
- // new PCEPSvecObject(true, false, true, false, true, requestIDs, true));
- // }
- //
- // /**
- // * Test for lowest bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
- // * Used resources:<br/>
- // * - PCEPSvecObject2.bin<br/>
- // *
- // * @throws IOException
- // * @throws PCEPDeserializerException
- // * @throws PCEPDocumentedException
- // */
- // @Test
- // public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException,
- // PCEPDocumentedException {
- // final List<Long> requestIDs = new ArrayList<Long>();
- // requestIDs.add(0xFFL);
- // serDeserTest("src/test/resources/PCEPSvecObject2.bin", new PCEPSvecObject(false, false, false, false, false,
- // requestIDs, false));
- // }
- //
- // @Test
- // public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
- // final PCEPClassTypeObject ct = new PCEPClassTypeObject((short) 4);
- // // final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
- // // final byte[] bytes = parser.put(ct);
- // // assertEquals(ct, parser.parse(bytes, true, false));
- // }
+
+ @Test
+ public void testSvecObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPSvecObjectParser parser = new PCEPSvecObjectParser(this.tlvRegistry);
+ byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin");
+
+ final SvecBuilder builder = new SvecBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setLinkDiverse(false);
+ builder.setNodeDiverse(false);
+ builder.setSrlgDiverse(false);
+ builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+ result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin");
+
+ builder.setProcessingRule(true);
+ builder.setLinkDiverse(true);
+ builder.setSrlgDiverse(true);
+
+ final List<RequestId> requestIDs = Lists.newArrayList();
+ requestIDs.add(new RequestId(0xFFFFFFFFL));
+ requestIDs.add(new RequestId(0x00000000L));
+ requestIDs.add(new RequestId(0x01234567L));
+ requestIDs.add(new RequestId(0x89ABCDEFL));
+ requestIDs.add(new RequestId(0xFEDCBA98L));
+ requestIDs.add(new RequestId(0x76543210L));
+ requestIDs.add(new RequestId(0x15825266L));
+ requestIDs.add(new RequestId(0x48120BBEL));
+ requestIDs.add(new RequestId(0x25FB7E52L));
+ requestIDs.add(new RequestId(0xB2F2546BL));
+
+ builder.setRequestsIds(requestIDs);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser(this.tlvRegistry);
+ final byte[] result = new byte[] { 0, 0, 0, (byte) 0x04 };
+
+ final ClassTypeBuilder builder = new ClassTypeBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setClassType(new ClassType((short) 4));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
//
// /**
// * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
//
// }
//
- // @Test
- // public void tesObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
- // serDeserTest("src/test/resources/PCEPObjectiveFunctionObject.1.bin", new
- // PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false));
- // }
- //
- // @Test
- // public void tesGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
- // serDeserTest("src/test/resources/PCEPGlobalConstraintsObject.1.bin",
- // new PCEPGlobalConstraintsObject((short) 1, (short) 0, (short) 100, (short) 0xFF, true, false));
- // }
- //
+
+ @Test
+ public void testSrpObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPSrpObjectParser parser = new PCEPSrpObjectParser(this.tlvRegistry);
+ final byte[] result = new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte) 0x01 };
+
+ final SrpBuilder builder = new SrpBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setOperationId(new SrpIdNumber(1L));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry);
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin");
+
+ final OfBuilder builder = new OfBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setCode(new OfId(4));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+ final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry);
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin");
+
+ final GcBuilder builder = new GcBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setMaxHop((short) 1);
+ builder.setMaxUtilization((short) 0);
+ builder.setMinUtilization((short) 100);
+ builder.setOverBookingFactor((short) 0xFF);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
// // FIXME: add at least one test with true value
// @Test
// public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException {
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+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.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedBuilder;
+
+public class PCEPRROSubobjectParserTest {
+
+ private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x01 };
+ private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0x16, (byte) 0x02 };
+ private static final byte[] unnumberedBytes = { (byte) 0x02, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+ private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
+ private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+ private static final byte[] labelBytes = { (byte) 0x81, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+
+ @Test
+ public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
+ final RROIpPrefixSubobjectParser parser = new RROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setProtectionAvailable(true);
+ subs.setProtectionInUse(false);
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
+ assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes));
+ assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROIp6PrefixSubobject() throws PCEPDeserializerException {
+ final RROIpPrefixSubobjectParser parser = new RROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setProtectionAvailable(false);
+ subs.setProtectionInUse(true);
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
+ assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes));
+ assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROUnnumberedSubobject() throws PCEPDeserializerException {
+ final RROUnnumberedInterfaceSubobjectParser parser = new RROUnnumberedInterfaceSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setProtectionAvailable(false);
+ subs.setProtectionInUse(true);
+ subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
+ assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes));
+ assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROPathKey32Subobject() throws PCEPDeserializerException {
+ final RROPathKeySubobjectParser parser = new RROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes));
+ assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROPathKey128Subobject() throws PCEPDeserializerException {
+ final RROPathKeySubobjectParser parser = new RROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+ (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes));
+ assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROLabelSubobject() throws Exception {
+ final RROLabelSubobjectParser parser = new RROLabelSubobjectParser(PCEPExtensionProviderContextImpl.create().getLabelHandlerRegistry());
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setSubobjectType(new LabelBuilder().setUniDirectional(true).setGlobal(true).setLabelType(
+ new GeneralizedLabelBuilder().setGeneralizedLabel(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(labelBytes));
+ assertArrayEquals(labelBytes, parser.serializeSubobject(subs.build()));
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.pcep.impl;
-
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
-
-/**
- * Tests for subobjects
- */
-public class PCEPSubobjectParserTest {
- final byte[] ipv6bytes1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
- final byte[] ipv6bytes2 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12,
- (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
-
- final byte[] ipv4bytes1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
- final byte[] ipv4bytes2 = { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
-
- final byte[] asnumber = { (byte) 0xA0, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64 };
-
- @Test
- public void testSerDeser() throws PCEPDeserializerException, IOException {
- // final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfSubobjects.bin");
- // final List<ExplicitRouteSubobject> objsToTest = PCEPEROSubobjectParser.parse(bytesFromFile);
- //
- // assertEquals(8, objsToTest.size());
-
- // final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
- // final CSubobject s = parser.parseSubobject(ByteArray.cutBytes(this.asnumber, 2));
- //
- // assertEquals(s, new AsNumberBuilder().setAsNumber(new AsNumber((long) 0x64)).build());
- // assertEquals(objsToTest.get(1), new AsNumberBuilder().setAsNumber(new AsNumber(0x0010L)).build());
-
- // assertEquals(objsToTest.get(2), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
- // IPv4Address(this.ipv4bytes1), 0x20), true));
- //
- // assertEquals(objsToTest.get(3), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
- // IPv4Address(this.ipv4bytes2), 0x15), false));
- // assertEquals(objsToTest.get(4), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
- // IPv6Address(this.ipv6bytes1), 0x80), true));
- //
- // assertEquals(objsToTest.get(5), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
- // IPv6Address(this.ipv6bytes2), 0x16), false));
- // final byte[] addr1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
- // assertEquals(objsToTest.get(6),
- // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr1), new UnnumberedInterfaceIdentifier(0xFFFFFFFFL),
- // true));
- //
- // final byte[] addr2 = { (byte) 0x01, (byte) 0x24, (byte) 0x56, (byte) 0x78 };
- // assertEquals(objsToTest.get(7),
- // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr2), new UnnumberedInterfaceIdentifier(0x9ABCDEF0L),
- // false));
- //
- // assertArrayEquals(bytesFromFile, PCEPEROSubobjectParser.put(objsToTest));
-
- }
-
- @Test
- @Ignore
- public void testEROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
- // final List<ExplicitRouteSubobject> objsToTest = new ArrayList<ExplicitRouteSubobject>();
- // objsToTest.add(new EROType1LabelSubobject(0xFFFF51F2L, true, false));
- // objsToTest.add(new EROType1LabelSubobject(0x12345648L, false, true));
- // objsToTest.add(new EROGeneralizedLabelSubobject(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte)
- // 0xFF }, true, true));
- // objsToTest.add(new EROWavebandSwitchingLabelSubobject(0x12345678L, 0x87654321L, 0xFFFFFFFFL, false, false));
- // objsToTest.add(new EROPathKeyWith32PCEIDSubobject(0x1235, new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF,
- // (byte) 0xF1 }, true));
- // objsToTest.add(new EROPathKeyWith128PCEIDSubobject(0x5432, new byte[] { (byte) 0x00, (byte) 0x55, (byte)
- // 0xFF, (byte) 0xF1,
- // (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
- // (byte) 0x00,
- // (byte) 0x55, (byte) 0xFF, (byte) 0xF1 }, true));
- // objsToTest.add(new EROExplicitExclusionRouteSubobject(Arrays.asList((ExcludeRouteSubobject) new
- // XROAsNumberSubobject(new AsNumber((long) 2588), true))));
-
- // assertEquals(objsToTest, PCEPEROSubobjectParser.parse(PCEPEROSubobjectParser.put(objsToTest)));
- }
-
- @Test
- public void testRROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
- // final List<ReportedRouteSubobject> objsToTest = new ArrayList<ReportedRouteSubobject>();
- // objsToTest.add(new RROIPAddressSubobject(new IpPrefix(Ipv6Util.prefixForBytes(this.ipv6bytes2, 0x16)), true,
- // false));
- // objsToTest.add(new RROIPAddressSubobject(new IpPrefix(Ipv4Util.prefixForBytes(this.ipv4bytes1, 0x16)), true,
- // false));
- // objsToTest.add(new RROType1LabelSubobject(0xFFFF51F2L, true));
- // objsToTest.add(new RROType1LabelSubobject(0x12345648L, false));
- // objsToTest.add(new RROGeneralizedLabelSubobject(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte)
- // 0xFF }, true));
- // objsToTest.add(new RROWavebandSwitchingLabelSubobject(0x12345678L, 0x87654321L, 0xFFFFFFFFL, false));
- // objsToTest.add(new RROPathKeyWith32PCEIDSubobject(0x1235, new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF,
- // (byte) 0xF1 }));
- // objsToTest.add(new RROPathKeyWith128PCEIDSubobject(0x5432, new byte[] { (byte) 0x00, (byte) 0x55, (byte)
- // 0xFF, (byte) 0xF1,
- // (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
- // (byte) 0x00,
- // (byte) 0x55, (byte) 0xFF, (byte) 0xF1 }));
- // objsToTest.add(new RROAttributesSubobject(new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
- // (byte) 0x00,
- // (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00,
- // (byte) 0x55,
- // (byte) 0xFF, (byte) 0xF1 }));
-
- // assertEquals(objsToTest, PCEPRROSubobjectParser.parse(PCEPRROSubobjectParser.put(objsToTest)));
- }
-
- @Test
- public void testXROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
- // final List<ExcludeRouteSubobject> objsToTest = new ArrayList<ExcludeRouteSubobject>();
- // objsToTest.add(new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(this.ipv6bytes2, 0x16)), true,
- // XROSubobjectAttribute.INTERFACE));
- // objsToTest.add(new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(this.ipv4bytes1, 0x16)), false,
- // XROSubobjectAttribute.INTERFACE));
- // objsToTest.add(new XROAsNumberSubobject(new AsNumber((long) 0x1234), true));
- // objsToTest.add(new XROUnnumberedInterfaceSubobject(new IPv4Address(this.ipv4bytes1), new
- // UnnumberedInterfaceIdentifier(0xFFFFFFFFL), true, XROSubobjectAttribute.SRLG));
- // objsToTest.add(new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
-
- // assertEquals(objsToTest, PCEPXROSubobjectParser.parse(PCEPXROSubobjectParser.put(objsToTest)));
- }
-
- //
- // @Test
- // public void testDifferentLengthExceptions() {
- // final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
- // // for parsing subobjects
- //
- // try {
- // EROAsNumberSubobjectParser.parse(bytes, true);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- //
- // try {
- // EROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- //
- // try {
- // EROIpPrefixSubobjectParser.parse(bytes, true);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- // }
-
- @Test
- public void testNullExceptions() throws PCEPDeserializerException {
- final byte[] bytes = null; // not empty but not enought data for parsing
- // subobjects
-
- try {
- new EROAsNumberSubobjectParser().parseSubobject(bytes, false);
- fail("");
- } catch (final IllegalArgumentException e) {
- }
-
- try {
- new EROUnnumberedInterfaceSubobjectParser().parseSubobject(bytes, false);
- fail("");
- } catch (final IllegalArgumentException e) {
- }
-
- try {
- new EROIpPrefixSubobjectParser().parseSubobject(bytes, false);
- fail("");
- } catch (final IllegalArgumentException e) {
- }
- }
-
- @Test
- public void testUnknownInstanceExceptions() {
-
- // final ExplicitRouteSubobject instance = new ExplicitRouteSubobject() {
- // };
-
- // try {
- // new EROAsNumberSubobjectParser().serializeSubobject(instance);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // EROUnnumberedInterfaceSubobjectParser.put(instance);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
-
- // try {
- // EROIpPrefixSubobjectParser.put(instance);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
-
- // try {
- // final byte[] ipv6addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- // (byte) 0x00,
- // (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- // (byte) 0x00 };
- // EROIpPrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(ipv6addr),
- // 1), false));
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // EROIPv6PrefixSubobjectParser.put(instance);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // final byte[] ipv4addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
- // EROIPv6PrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
- // IPv4Address(ipv4addr), 1), false));
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
-
- }
-}
*/
package org.opendaylight.protocol.pcep.impl;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigInteger;
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PredundancyGroupTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspErrorCodeTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfListTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OrderTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OverloadDurationTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PredundancyGroupIdTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReqMissingTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspErrorCodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.RsvpErrorSpecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymbolicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.tlvs.OverloadDurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.LspDbVersionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.OfListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.PredundancyGroupIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.tlvs.ReqMissingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.tlvs.NoPathVectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.tlvs.OrderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.RsvpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.UserBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
+
+import com.google.common.collect.Lists;
-/**
- * Tests of PCEPTlvParser
- */
public class PCEPTlvParserTest {
- // @Test
- // public void testDeserialization() throws PCEPDeserializerException, IOException {
- // final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfTlvs.bin");
- // final List<PCEPTlv> tlvsToTest = PCEPTlvParser.parseTlv(bytesFromFile);
- //
- // assertEquals(17, tlvsToTest.size());
- // assertEquals(tlvsToTest.get(0), new PCEStatefulCapabilityTlv(false, false, true));
- // assertEquals(tlvsToTest.get(1), new LSPStateDBVersionTlv(0xFF00FFAAB2F5F2CFL));
- // assertEquals(tlvsToTest.get(2), new PCEStatefulCapabilityTlv(false, true, true));
- // assertEquals(tlvsToTest.get(3), new LSPStateDBVersionTlv(0xFFFFFFFFFFFFFFFFL));
- // assertEquals(tlvsToTest.get(4), new NoPathVectorTlv(true, true, true, false, true, true));
- // assertEquals(tlvsToTest.get(5), new OverloadedDurationTlv(0x7FFFFFFF));
- // assertEquals(tlvsToTest.get(6), new LSPSymbolicNameTlv(new LSPSymbolicName(new
- // String("Med test of symbolic name").getBytes())));
- // final byte[] errorCode = { (byte) 0x25, (byte) 0x68, (byte) 0x95, (byte) 0x03 };
- // assertEquals(tlvsToTest.get(7), new LSPUpdateErrorTlv(errorCode));
- // final byte[] ipv4Address = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
- // final byte[] tunnelId1 = { (byte) 0x12, (byte) 0x34 };
- // final byte[] extendedTunnelID1 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
- // final byte[] lspId1 = { (byte) 0xFF, (byte) 0xFF };
- // assertEquals(tlvsToTest.get(8), new IPv4LSPIdentifiersTlv(new IPv4Address(ipv4Address),
- // new LSPIdentifier(lspId1), new TunnelIdentifier(tunnelId1), new IPv4ExtendedTunnelIdentifier(new
- // IPv4Address(extendedTunnelID1))));
- // final byte[] ipv6Address = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte)
- // 0xDE, (byte) 0xF0, (byte) 0x12,
- // (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 };
- // final byte[] tunnelId2 = { (byte) 0xFF, (byte) 0xFF };
- // final byte[] extendedTunnelID2 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x12, (byte) 0x34,
- // (byte) 0x56, (byte) 0x78, (byte) 0x01,
- // (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 };
- // final byte[] lspId2 = { (byte) 0x12, (byte) 0x34 };
- // assertEquals(tlvsToTest.get(9), new IPv6LSPIdentifiersTlv(new IPv6Address(ipv6Address),
- // new LSPIdentifier(lspId2), new TunnelIdentifier(tunnelId2), new IPv6ExtendedTunnelIdentifier(new
- // IPv6Address(extendedTunnelID2))));
- // assertEquals(tlvsToTest.get(10), new RSVPErrorSpecTlv<IPv4Address>(new IPv4Address(ipv4Address), false, true,
- // 0x92, 0x1602));
- // assertEquals(tlvsToTest.get(11), new RSVPErrorSpecTlv<IPv6Address>(new IPv6Address(ipv6Address), true, false,
- // 0xD5, 0xC5D9));
- // assertEquals(tlvsToTest.get(12), new ReqMissingTlv(0xF7823517L));
- // final byte[] valueBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
- // assertEquals(tlvsToTest.get(13), new NodeIdentifierTlv(valueBytes));
- // assertEquals(tlvsToTest.get(14), new OrderTlv(0xFFFFFFFFL, 0x00000001L));
- // assertEquals(tlvsToTest.get(15), new OFListTlv(new ArrayList<PCEPOFCodes>() {
- // private static final long serialVersionUID = 1L;
- //
- // {
- // this.add(PCEPOFCodes.MCC);
- // this.add(PCEPOFCodes.MCP);
- // this.add(PCEPOFCodes.MLL);
- // }
- // }));
- // assertEquals(tlvsToTest.get(16), new P2MPCapabilityTlv(2));
- //
- // assertArrayEquals(bytesFromFile, PCEPTlvParser.put(tlvsToTest));
- // }
- //
- // @Test
- // public void testDifferentLengthExceptions() {
- // final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
- // // for parsing subobjects
- //
- // try {
- // LSPIdentifierIPv4TlvParser.parse(bytes);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- //
- // try {
- // LSPIdentifierIPv6TlvParser.parse(bytes);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- //
- // try {
- // PCEStatefulCapabilityTlvParser.deserializeValueField(bytes);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- //
- // try {
- // RSVPErrorSpecTlvParser.parse(bytes);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- //
- // try {
- // RSVPErrorSpecIPv6TlvParser.parse(bytes);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- //
- // try {
- // OFListTlvParser.parse(bytes);
- // fail("");
- // } catch (final PCEPDeserializerException e) {
- // }
- // }
- //
- // @Test
- // public void testUnknownInstanceExceptions() {
- // try {
- // LSPIdentifierIPv4TlvParser.put(null);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // LSPIdentifierIPv6TlvParser.put(null);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // PCEStatefulCapabilityTlvParser.serializeValueField(null);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // RSVPErrorSpecTlvParser.put(null);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // RSVPErrorSpecIPv6TlvParser.put(null);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // OFListTlvParser.put(null);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // }
- //
- // @Test
- // public void testEmptyExceptions() throws PCEPDeserializerException {
- // final byte[] bytes = {}; // empty
- //
- // try {
- // LSPIdentifierIPv4TlvParser.parse(bytes);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // LSPIdentifierIPv6TlvParser.parse(bytes);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // PCEStatefulCapabilityTlvParser.deserializeValueField(bytes);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // RSVPErrorSpecTlvParser.parse(bytes);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // RSVPErrorSpecIPv6TlvParser.parse(bytes);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- //
- // try {
- // OFListTlvParser.parse(bytes);
- // fail("");
- // } catch (final IllegalArgumentException e) {
- // }
- // }
+ private static final byte[] statefulBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02 };
+ private static final byte[] DbVersionBytes = { (byte) 0xff, (byte) 0x00, (byte) 0xff, (byte) 0xaa, (byte) 0xb2, (byte) 0xf5,
+ (byte) 0xf2, (byte) 0xcf };
+ private static final byte[] noPathVectorBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xa7 };
+ private static final byte[] overloadedBytes = { (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff };
+ private static final byte[] symbolicNameBytes = { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65,
+ (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d,
+ (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d,
+ (byte) 0x65 };
+ private static final byte[] lspUpdateErrorBytes = { (byte) 0x25, (byte) 0x68, (byte) 0x95, (byte) 0x03 };
+ private static final byte[] lspIdentifiers4Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+ private static final byte[] lspIdentifiers6Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC,
+ (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+ (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0xFF, (byte) 0xFF, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x01,
+ (byte) 0x23, (byte) 0x45, (byte) 0x67 };
+ private static final byte[] rsvpErrorBytes = { (byte) 0x06, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x02, (byte) 0x92, (byte) 0x16, (byte) 0x02 };
+ private static final byte[] rsvpError6Bytes = { (byte) 0x06, (byte) 0x02, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
+ (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x02, (byte) 0xd5, (byte) 0xc5, (byte) 0xd9 };
+ private static final byte[] userErrorBytes = { (byte) 0xc2, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x39,
+ (byte) 0x05, (byte) 0x09, (byte) 0x00, (byte) 0x26, (byte) 0x75, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x20,
+ (byte) 0x64, (byte) 0x65, (byte) 0x73, (byte) 0x63 };
+ private static final byte[] reqMissingBytes = { (byte) 0xF7, (byte) 0x82, (byte) 0x35, (byte) 0x17 };
+ private static final byte[] orderBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x01 };
+ private static final byte[] ofListBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+ private static final byte[] predundancyBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+
+ @Test
+ public void testStatefulTlv() throws PCEPDeserializerException {
+ final PCEStatefulCapabilityTlvParser parser = new PCEStatefulCapabilityTlvParser();
+ final StatefulCapabilityTlv tlv = new StatefulBuilder().setFlags(new Flags(true, false, false)).build();
+ assertEquals(tlv, parser.parseTlv(statefulBytes));
+ assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testStateDbVersionTlv() throws PCEPDeserializerException {
+ final LspDbVersionTlvParser parser = new LspDbVersionTlvParser();
+ final LspDbVersionTlv tlv = new LspDbVersionBuilder().setVersion(BigInteger.valueOf(0xFF00FFAAB2F5F2CFL)).build();
+ assertEquals(tlv, parser.parseTlv(DbVersionBytes));
+ assertArrayEquals(DbVersionBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testNoPathVectorTlv() throws PCEPDeserializerException {
+ final NoPathVectorTlvParser parser = new NoPathVectorTlvParser();
+ final NoPathVectorTlv tlv = new NoPathVectorBuilder().setFlags(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)).build();
+ assertEquals(tlv, parser.parseTlv(noPathVectorBytes));
+ assertArrayEquals(noPathVectorBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testOverloadedDurationTlv() throws PCEPDeserializerException {
+ final OverloadedDurationTlvParser parser = new OverloadedDurationTlvParser();
+ final OverloadDurationTlv tlv = new OverloadDurationBuilder().setDuration(0x7FFFFFFFL).build();
+ assertEquals(tlv, parser.parseTlv(overloadedBytes));
+ assertArrayEquals(overloadedBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testSymbolicNameTlv() throws PCEPDeserializerException {
+ final LspSymbolicNameTlvParser parser = new LspSymbolicNameTlvParser();
+ final SymbolicPathNameTlv tlv = new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("Med test of symbolic name".getBytes())).build();
+ assertEquals(tlv, parser.parseTlv(symbolicNameBytes));
+ assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testLspErrorCodeTlv() throws PCEPDeserializerException {
+ final LspUpdateErrorTlvParser parser = new LspUpdateErrorTlvParser();
+ final LspErrorCodeTlv tlv = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
+ assertEquals(tlv, parser.parseTlv(lspUpdateErrorBytes));
+ assertArrayEquals(lspUpdateErrorBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testLspIdentifiers4Tlv() throws PCEPDeserializerException {
+ final LSPIdentifierTlvParser parser = new LSPIdentifierTlvParser();
+ final Ipv4Builder afi = new Ipv4Builder();
+ afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
+ afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+ (byte) 0x78 })));
+ final LspIdentifiersTlv tlv = new LspIdentifiersBuilder().setAddressFamily(afi.build()).setLspId(new LspId(65535L)).setTunnelId(
+ new TunnelId(4660)).build();
+ assertEquals(tlv, parser.parseTlv(lspIdentifiers4Bytes));
+ assertArrayEquals(lspIdentifiers4Bytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testLspIdentifiers6Tlv() throws PCEPDeserializerException {
+ final LSPIdentifierTlvParser parser = new LSPIdentifierTlvParser();
+ final Ipv6Builder afi = new Ipv6Builder();
+ afi.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
+ (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 }));
+ afi.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+ (byte) 0x78, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
+ (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 })));
+ final LspIdentifiersTlv tlv = new LspIdentifiersBuilder().setAddressFamily(afi.build()).setLspId(new LspId(4660L)).setTunnelId(
+ new TunnelId(65535)).build();
+ assertEquals(tlv, parser.parseTlv(lspIdentifiers6Bytes));
+ assertArrayEquals(lspIdentifiers6Bytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testRSVPError4SpecTlv() throws PCEPDeserializerException {
+ final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+ final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+ builder.setNode(new IpAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+ builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
+ builder.setCode((short) 146);
+ builder.setValue(5634);
+ final RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpBuilder().setRsvpError(builder.build()).build()).build();
+ assertEquals(tlv, parser.parseTlv(rsvpErrorBytes));
+ assertArrayEquals(rsvpErrorBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testRSVPError6SpecTlv() throws PCEPDeserializerException {
+ final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+ final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+ builder.setNode(new IpAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
+ (byte) 0xbc, (byte) 0xde, (byte) 0xf0 })));
+ builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
+ builder.setCode((short) 213);
+ builder.setValue(50649);
+ final RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpBuilder().setRsvpError(builder.build()).build()).build();
+ assertEquals(tlv, parser.parseTlv(rsvpError6Bytes));
+ assertArrayEquals(rsvpError6Bytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testUserErrorSpecTlv() throws PCEPDeserializerException {
+ final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+ final UserErrorBuilder builder = new UserErrorBuilder();
+ builder.setEnterprise(new EnterpriseNumber(12345L));
+ builder.setSubOrg((short) 5);
+ builder.setValue(38);
+ builder.setDescription("user desc");
+ final RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new UserBuilder().setUserError(builder.build()).build()).build();
+ assertEquals(tlv, parser.parseTlv(userErrorBytes));
+ assertArrayEquals(userErrorBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testReqMissingTlv() throws PCEPDeserializerException {
+ final ReqMissingTlvParser parser = new ReqMissingTlvParser();
+ final ReqMissingTlv tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build();
+ assertEquals(tlv, parser.parseTlv(reqMissingBytes));
+ assertArrayEquals(reqMissingBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testOrderTlv() throws PCEPDeserializerException {
+ final OrderTlvParser parser = new OrderTlvParser();
+ final OrderTlv tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build();
+ assertEquals(tlv, parser.parseTlv(orderBytes));
+ assertArrayEquals(orderBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testOFListTlv() throws PCEPDeserializerException {
+ final OFListTlvParser parser = new OFListTlvParser();
+ final List<OfId> ids = Lists.newArrayList();
+ ids.add(new OfId(0x1234));
+ ids.add(new OfId(0x5678));
+ final OfListTlv tlv = new OfListBuilder().setCodes(ids).build();
+ assertEquals(tlv, parser.parseTlv(ofListBytes));
+ assertArrayEquals(ofListBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testPredundancyTlv() throws PCEPDeserializerException {
+ final PredundancyGroupTlvParser parser = new PredundancyGroupTlvParser();
+ final PredundancyGroupIdTlv tlv = new PredundancyGroupIdBuilder().setIdentifier(predundancyBytes).build();
+ assertEquals(tlv, parser.parseTlv(predundancyBytes));
+ assertArrayEquals(predundancyBytes, parser.serializeTlv(tlv));
+ }
}
*/
package org.opendaylight.protocol.pcep.impl;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv6Util;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+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.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.SrlgBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
public class PCEPXROSubobjectParserTest {
- @Test
- public void testSerDeser() throws PCEPDeserializerException, IOException {
- final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfXROSubobjects.bin");
- // final List<ExcludeRouteSubobject> objsToTest = PCEPXROSubobjectParser.parse(bytesFromFile);
+ private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
+ private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0x16, (byte) 0x01 };
+ private static final byte[] srlgBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x02 };
+ private static final byte[] unnumberedBytes = { (byte) 0x00, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+ private static final byte[] asNumberBytes = { (byte) 0x00, (byte) 0x64 };
+ private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
+ private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00 };
- // assertEquals(5, objsToTest.size());
- //
- // assertEquals(
- // objsToTest.get(0),
- // new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(new byte[] { (byte) 192, (byte) 168, (byte) 0,
- // (byte) 0 }, 16)), true, XROSubobjectAttribute.NODE));
- // assertEquals(
- // objsToTest.get(1),
- // new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte)
- // 0x56,
- // (byte) 0x78, (byte) 0x90, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x90, (byte) 0x12,
- // (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0, (byte) 0 }, 112)), true, XROSubobjectAttribute.INTERFACE));
- // assertEquals(objsToTest.get(2), new XROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 0,
- // (byte) 0, (byte) 0,
- // (byte) 0x20 }), new UnnumberedInterfaceIdentifier(0x1234L), false, XROSubobjectAttribute.SRLG));
- // assertEquals(objsToTest.get(3), new XROAsNumberSubobject(new AsNumber((long) 0x1234), false));
- // assertEquals(objsToTest.get(4), new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
+ @Test
+ public void testXROIp4PrefixSubobject() throws PCEPDeserializerException {
+ final XROIpPrefixSubobjectParser parser = new XROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setMandatory(false);
+ subs.setAttribute(Attribute.Interface);
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
+ assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes, false));
+ assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
- // assertArrayEquals(bytesFromFile, PCEPXROSubobjectParser.put(objsToTest));
+ @Test
+ public void testXROIp6PrefixSubobject() throws PCEPDeserializerException {
+ final XROIpPrefixSubobjectParser parser = new XROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setMandatory(true);
+ subs.setAttribute(Attribute.Node);
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
+ assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes, true));
+ assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
+ @Test
+ public void testXROSrlgSubobject() throws PCEPDeserializerException {
+ final XROSRLGSubobjectParser parser = new XROSRLGSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setMandatory(true);
+ subs.setAttribute(Attribute.Srlg);
+ subs.setSubobjectType(new SrlgBuilder().setSrlgId(new SrlgId(0x12345678L)).build());
+ assertEquals(subs.build(), parser.parseSubobject(srlgBytes, true));
+ assertArrayEquals(srlgBytes, parser.serializeSubobject(subs.build()));
}
@Test
- public void testDifferentLengthExceptions() {
- final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data for parsing subobjects
+ public void testXROUnnumberedSubobject() throws PCEPDeserializerException {
+ final XROUnnumberedInterfaceSubobjectParser parser = new XROUnnumberedInterfaceSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setMandatory(true);
+ subs.setAttribute(Attribute.Node);
+ subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
+ assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes, true));
+ assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
+ }
- try {
- new XROAsNumberSubobjectParser().parseSubobject(bytes, true);
- fail("");
- } catch (final PCEPDeserializerException e) {
- }
+ @Test
+ public void testXROAsNumberSubobject() throws PCEPDeserializerException {
+ final XROAsNumberSubobjectParser parser = new XROAsNumberSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setMandatory(true);
+ subs.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
+ assertEquals(subs.build(), parser.parseSubobject(asNumberBytes, true));
+ assertArrayEquals(asNumberBytes, parser.serializeSubobject(subs.build()));
+ }
- try {
- new XROUnnumberedInterfaceSubobjectParser().parseSubobject(bytes, true);
- fail("");
- } catch (final PCEPDeserializerException e) {
- }
+ @Test
+ public void testXROPathKey32Subobject() throws PCEPDeserializerException {
+ final XROPathKeySubobjectParser parser = new XROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setMandatory(true);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes, true));
+ assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
+ }
- try {
- new XROIpPrefixSubobjectParser().parseSubobject(bytes, true);
- fail("");
- } catch (final PCEPDeserializerException e) {
- }
+ @Test
+ public void testXROPathKey128Subobject() throws PCEPDeserializerException {
+ final XROPathKeySubobjectParser parser = new XROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setMandatory(true);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+ (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes, true));
+ assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
}
}
import io.netty.channel.Channel;
import io.netty.util.HashedWheelTimer;
+import java.util.concurrent.Future;
+
import org.opendaylight.protocol.pcep.PCEPCloseTermination;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.protocol.pcep.TerminationReason;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
+import com.google.common.util.concurrent.Futures;
+
public class ServerSessionMock extends PCEPSessionImpl {
private final MockPCE client;
}
@Override
- public void sendMessage(final Message msg) {
+ public Future<Void> sendMessage(final Message msg) {
this.lastMessageSentAt = System.nanoTime();
this.client.onMessage(this, msg);
+ return Futures.immediateFuture(null);
}
@Override
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
<Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
<Export-Package>
org.opendaylight.protocol.pcep.spi,
+ org.opendaylight.protocol.pcep.spi.osgi,
</Export-Package>
+ <Private-Package>
+ org.opendaylight.protocol.pcep.spi.pojo,
+ </Private-Package>
</instructions>
</configuration>
</plugin>
package org.opendaylight.protocol.pcep.spi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
public interface EROSubobjectHandlerRegistry {
- public AutoCloseable registerSubobjectParser(int subobjectType, EROSubobjectParser parser);
-
public EROSubobjectParser getSubobjectParser(int subobjectType);
-
- public AutoCloseable registerSubobjectSerializer(Class<? extends CSubobject> subobjectClass, EROSubobjectSerializer serializer);
-
public EROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
}
*/
package org.opendaylight.protocol.pcep.spi;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
public interface LabelHandlerRegistry {
- public AutoCloseable registerLabelParser(int cType, LabelParser parser);
public LabelParser getLabelParser(int cType);
- public AutoCloseable registerLabelSerializer(Class<? extends CLabel> labelClass, LabelSerializer serializer);
- public LabelSerializer getLabelSerializer(CLabel label);
+ public LabelSerializer getLabelSerializer(LabelType label);
}
*/
package org.opendaylight.protocol.pcep.spi;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
public interface LabelSerializer {
@Deprecated
public int getType();
- public byte[] serializeSubobject(CLabel subobject);
+ public byte[] serializeLabel(LabelType subobject);
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
public interface MessageHandlerRegistry {
- public AutoCloseable registerMessageParser(int messageType, MessageParser parser);
- public AutoCloseable registerMessageSerializer(Class<? extends Message> msgClass, MessageSerializer serializer);
-
public MessageParser getMessageParser(int messageType);
public MessageSerializer getMessageSerializer(Message message);
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
public interface ObjectHandlerRegistry {
- public AutoCloseable registerObjectParser(int objectClass, int objectType, ObjectParser parser);
- public AutoCloseable registerObjectSerializer(Class<? extends Object> objClass, ObjectSerializer serializer);
-
public ObjectParser getObjectParser(int objectClass, int objectType);
public ObjectSerializer getObjectSerializer(Object object);
}
*/
package org.opendaylight.protocol.pcep.spi;
-public interface PCEPProviderActivator {
- public void start(PCEPProviderContext context);
+public interface PCEPExtensionConsumerActivator {
+ public void start(PCEPExtensionConsumerContext context);
public void stop();
}
\ No newline at end of file
*/
package org.opendaylight.protocol.pcep.spi;
-public interface PCEPProviderContext {
+public interface PCEPExtensionConsumerContext {
public LabelHandlerRegistry getLabelHandlerRegistry();
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.spi;
+
+public interface PCEPExtensionProviderActivator {
+ public void start(PCEPExtensionProviderContext context) throws Exception;
+ public void stop() throws Exception;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+
+public interface PCEPExtensionProviderContext extends PCEPExtensionConsumerContext {
+ public AutoCloseable registerLabelSerializer(Class<? extends LabelType> labelClass, LabelSerializer serializer);
+
+ public AutoCloseable registerLabelParser(int cType, LabelParser parser);
+
+ public AutoCloseable registerEROSubobjectParser(int subobjectType, EROSubobjectParser parser);
+
+ public AutoCloseable registerEROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, EROSubobjectSerializer serializer);
+
+ public AutoCloseable registerMessageParser(int messageType, MessageParser parser);
+
+ public AutoCloseable registerMessageSerializer(Class<? extends Message> msgClass, MessageSerializer serializer);
+
+ public AutoCloseable registerObjectParser(int objectClass, int objectType, ObjectParser parser);
+
+ public AutoCloseable registerObjectSerializer(Class<? extends Object> objClass, ObjectSerializer serializer);
+
+ public AutoCloseable registerRROSubobjectParser(int subobjectType, RROSubobjectParser parser);
+
+ public AutoCloseable registerRROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, RROSubobjectSerializer serializer);
+
+ public AutoCloseable registerTlvSerializer(Class<? extends Tlv> tlvClass, TlvSerializer serializer);
+
+ public AutoCloseable registerTlvParser(int tlvType, TlvParser parser);
+
+ public AutoCloseable registerXROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, XROSubobjectSerializer serializer);
+
+ public AutoCloseable registerXROSubobjectParser(int subobjectType, XROSubobjectParser parser);
+}
package org.opendaylight.protocol.pcep.spi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
public interface RROSubobjectHandlerRegistry {
- public AutoCloseable registerSubobjectParser(int subobjectType, RROSubobjectParser parser);
-
public RROSubobjectParser getSubobjectParser(int subobjectType);
-
- public AutoCloseable registerSubobjectSerializer(Class<? extends CSubobject> subobjectClass, RROSubobjectSerializer serializer);
-
public RROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
public interface TlvHandlerRegistry {
- public AutoCloseable registerTlvParser(int tlvType, TlvParser parser);
public TlvParser getTlvParser(int tlvType);
-
- public AutoCloseable registerTlvSerializer(Class<? extends Tlv> tlvClass, TlvSerializer serializer);
public TlvSerializer getTlvSerializer(Tlv tlv);
}
package org.opendaylight.protocol.pcep.spi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
public interface XROSubobjectHandlerRegistry {
-
- public AutoCloseable registerSubobjectParser(int subobjectType, XROSubobjectParser parser);
-
public XROSubobjectParser getSubobjectParser(int subobjectType);
-
- public AutoCloseable registerSubobjectSerializer(Class<? extends CSubobject> subobjectClass, XROSubobjectSerializer serializer);
-
public XROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerContext;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import com.google.common.base.Preconditions;
+
+public abstract class AbstractOSGiPCEPExtensionConsumerActivator implements BundleActivator, PCEPExtensionConsumerActivator {
+ private PCEPExtensionConsumerContext consumerContext;
+
+ @Override
+ public final void start(final BundleContext context) throws Exception {
+ Preconditions.checkState(consumerContext == null);
+ final PCEPExtensionConsumerContext consumerContext = new OSGiPCEPExtensionConsumerContext(context);
+ start(consumerContext);
+ this.consumerContext = consumerContext;
+ }
+
+ @Override
+ public final void stop(final BundleContext context) throws Exception {
+ Preconditions.checkState(consumerContext != null);
+ try {
+ stop();
+ } finally {
+ consumerContext = null;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import com.google.common.base.Preconditions;
+
+public abstract class AbstractOSGiPCEPExtensionProviderActivator implements BundleActivator, PCEPExtensionProviderActivator {
+ private PCEPExtensionProviderContext providerContext;
+
+ @Override
+ public final void start(final BundleContext context) throws Exception {
+ Preconditions.checkState(providerContext == null);
+ final PCEPExtensionProviderContext providerContext = new OSGiPCEPExtensionProviderContext(context);
+ start(providerContext);
+ this.providerContext = providerContext;
+ }
+
+ @Override
+ public final void stop(final BundleContext context) throws Exception {
+ Preconditions.checkState(providerContext != null);
+ try {
+ stop();
+ } finally {
+ providerContext = null;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.osgi.framework.BundleContext;
+
+import com.google.common.base.Preconditions;
+
+class OSGiPCEPExtensionConsumerContext implements PCEPExtensionConsumerContext {
+ protected final BundleContext bundleContext;
+
+ public OSGiPCEPExtensionConsumerContext(final BundleContext context) {
+ this.bundleContext = Preconditions.checkNotNull(context);
+ }
+
+ @Override
+ public LabelHandlerRegistry getLabelHandlerRegistry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public MessageHandlerRegistry getMessageHandlerRegistry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ObjectHandlerRegistry getObjectHandlerRegistry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public TlvHandlerRegistry getTlvHandlerRegistry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelParser;
+import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.MessageParser;
+import org.opendaylight.protocol.pcep.spi.MessageSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.osgi.framework.BundleContext;
+
+class OSGiPCEPExtensionProviderContext extends OSGiPCEPExtensionConsumerContext implements PCEPExtensionProviderContext {
+ OSGiPCEPExtensionProviderContext(final BundleContext context) {
+ super(context);
+ }
+
+ @Override
+ public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerEROSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ final EROSubobjectSerializer serializer) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerMessageSerializer(final Class<? extends Message> msgClass, final MessageSerializer serializer) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerRROSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerRROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ final RROSubobjectSerializer serializer) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerXROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ final XROSubobjectSerializer serializer) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AutoCloseable registerXROSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.pcep.spi.pojo;
+
+import java.util.ServiceLoader;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelParser;
+import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.MessageParser;
+import org.opendaylight.protocol.pcep.spi.MessageSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+
+/**
+ *
+ */
+@ThreadSafe
+public final class PCEPExtensionProviderContextImpl implements PCEPExtensionProviderContext {
+ private static final class Holder {
+ private static final PCEPExtensionProviderContext INSTANCE;
+
+ static {
+ try {
+ INSTANCE = PCEPExtensionProviderContextImpl.create();
+ } catch (final Exception e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+ }
+
+ private final SimpleLabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
+ private final SimpleMessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
+ private final SimpleObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
+ private final SimpleEROSubobjectHandlerRegistry eroSubReg = new SimpleEROSubobjectHandlerRegistry();
+ private final SimpleRROSubobjectHandlerRegistry rroSubReg = new SimpleRROSubobjectHandlerRegistry();
+ private final SimpleXROSubobjectHandlerRegistry xroSubReg = new SimpleXROSubobjectHandlerRegistry();
+ private final SimpleTlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry();
+
+ protected PCEPExtensionProviderContextImpl() {
+
+ }
+
+ public static PCEPExtensionProviderContext create() throws Exception {
+ final PCEPExtensionProviderContext ctx = new PCEPExtensionProviderContextImpl();
+
+ final ServiceLoader<PCEPExtensionProviderActivator> loader = ServiceLoader.load(PCEPExtensionProviderActivator.class);
+ for (final PCEPExtensionProviderActivator a : loader) {
+ a.start(ctx);
+ }
+
+ return ctx;
+
+ }
+
+ public static PCEPExtensionProviderContext getSingletonInstance() {
+ return Holder.INSTANCE;
+ }
+
+ @Override
+ public LabelHandlerRegistry getLabelHandlerRegistry() {
+ return this.labelReg;
+ }
+
+ @Override
+ public MessageHandlerRegistry getMessageHandlerRegistry() {
+ return this.msgReg;
+ }
+
+ @Override
+ public ObjectHandlerRegistry getObjectHandlerRegistry() {
+ return this.objReg;
+ }
+
+ @Override
+ public EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
+ return this.eroSubReg;
+ }
+
+ @Override
+ public RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry() {
+ return this.rroSubReg;
+ }
+
+ @Override
+ public XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
+ return this.xroSubReg;
+ }
+
+ @Override
+ public TlvHandlerRegistry getTlvHandlerRegistry() {
+ return this.tlvReg;
+ }
+
+ @Override
+ public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
+ return this.labelReg.registerLabelSerializer(labelClass, serializer);
+ }
+
+ @Override
+ public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
+ return this.labelReg.registerLabelParser(cType, parser);
+ }
+
+ @Override
+ public AutoCloseable registerEROSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
+ return this.eroSubReg.registerSubobjectParser(subobjectType, parser);
+ }
+
+ @Override
+ public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ final EROSubobjectSerializer serializer) {
+ return this.eroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
+ }
+
+ @Override
+ public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
+ return this.msgReg.registerMessageParser(messageType, parser);
+ }
+
+ @Override
+ public AutoCloseable registerMessageSerializer(final Class<? extends Message> msgClass, final MessageSerializer serializer) {
+ return this.msgReg.registerMessageSerializer(msgClass, serializer);
+ }
+
+ @Override
+ public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
+ return this.objReg.registerObjectParser(objectClass, objectType, parser);
+ }
+
+ @Override
+ public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
+ return this.objReg.registerObjectSerializer(objClass, serializer);
+ }
+
+ @Override
+ public AutoCloseable registerRROSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
+ return this.rroSubReg.registerSubobjectParser(subobjectType, parser);
+ }
+
+ @Override
+ public AutoCloseable registerRROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ final RROSubobjectSerializer serializer) {
+ return this.rroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
+ }
+
+ @Override
+ public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
+ return this.tlvReg.registerTlvParser(tlvType, parser);
+ }
+
+ @Override
+ public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
+ return this.tlvReg.registerTlvSerializer(tlvClass, serializer);
+ }
+
+ @Override
+ public AutoCloseable registerXROSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
+ return this.xroSubReg.registerSubobjectParser(subobjectType, parser);
+ }
+
+ @Override
+ public AutoCloseable registerXROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ final XROSubobjectSerializer serializer) {
+ return this.xroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
+ }
+}
* 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.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleEROSubobjectHandlerFactory implements EROSubobjectHandlerRegistry {
+public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHandlerRegistry {
private final HandlerRegistry<DataContainer, EROSubobjectParser, EROSubobjectSerializer> handlers = new HandlerRegistry<>();
- @Override
public AutoCloseable registerSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+ Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
return this.handlers.registerParser(subobjectType, parser);
}
- @Override
- public EROSubobjectParser getSubobjectParser(final int subobjectType) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
- return this.handlers.getParser(subobjectType);
- }
-
- @Override
public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
final EROSubobjectSerializer serializer) {
return this.handlers.registerSerializer(subobjectClass, serializer);
}
+ @Override
+ public EROSubobjectParser getSubobjectParser(final int subobjectType) {
+ Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
+ return this.handlers.getParser(subobjectType);
+ }
+
@Override
public EROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
return this.handlers.getSerializer(subobject.getImplementedInterface());
* 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.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+import org.opendaylight.protocol.util.Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
public class SimpleLabelHandlerRegistry implements LabelHandlerRegistry {
private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
- @Override
public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
- Preconditions.checkArgument(cType >= 0 && cType <= 255);
- return handlers.registerParser(cType, parser);
+ Preconditions.checkArgument(cType >= 0 && cType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+ return this.handlers.registerParser(cType, parser);
}
- @Override
- public LabelParser getLabelParser(final int cType) {
- Preconditions.checkArgument(cType >= 0 && cType <= 255);
- return handlers.getParser(cType);
+ public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
+ return this.handlers.registerSerializer(labelClass, serializer);
}
@Override
- public AutoCloseable registerLabelSerializer(final Class<? extends CLabel> labelClass, final LabelSerializer serializer) {
- return handlers.registerSerializer(labelClass, serializer);
+ public LabelParser getLabelParser(final int cType) {
+ Preconditions.checkArgument(cType >= 0 && cType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+ return this.handlers.getParser(cType);
}
@Override
- public LabelSerializer getLabelSerializer(final CLabel label) {
- return handlers.getSerializer(label.getImplementedInterface());
+ public LabelSerializer getLabelSerializer(final LabelType label) {
+ return this.handlers.getSerializer(label.getImplementedInterface());
}
}
* 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.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.MessageParser;
import org.opendaylight.protocol.pcep.spi.MessageSerializer;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yangtools.yang.binding.DataContainer;
private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
- @Override
public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
- Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+ Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
return this.handlers.registerParser(messageType, parser);
}
- @Override
public AutoCloseable registerMessageSerializer(final Class<? extends Message> msgClass, final MessageSerializer serializer) {
return this.handlers.registerSerializer(msgClass, serializer);
}
@Override
public MessageParser getMessageParser(final int messageType) {
- Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+ Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
return this.handlers.getParser(messageType);
}
* 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.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yangtools.yang.binding.DataContainer;
public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry {
private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
- private static final int createKey(final int objectClass, final int objectType) {
- Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+ private static int createKey(final int objectClass, final int objectType) {
+ Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
return (objectClass << 4) | objectType;
}
- @Override
public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
- Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+ Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
- return handlers.registerParser(createKey(objectClass, objectType), parser);
+ return this.handlers.registerParser(createKey(objectClass, objectType), parser);
}
- @Override
public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
- return handlers.registerSerializer(objClass, serializer);
+ return this.handlers.registerSerializer(objClass, serializer);
}
@Override
public ObjectParser getObjectParser(final int objectClass, final int objectType) {
- return handlers.getParser(createKey(objectClass, objectType));
+ return this.handlers.getParser(createKey(objectClass, objectType));
}
@Override
public ObjectSerializer getObjectSerializer(final Object object) {
- return handlers.getSerializer(object.getImplementedInterface());
+ return this.handlers.getSerializer(object.getImplementedInterface());
}
}
* 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.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleRROSubobjectHandlerFactory implements RROSubobjectHandlerRegistry {
+public final class SimpleRROSubobjectHandlerRegistry implements RROSubobjectHandlerRegistry {
private final HandlerRegistry<DataContainer, RROSubobjectParser, RROSubobjectSerializer> handlers = new HandlerRegistry<>();
- @Override
public AutoCloseable registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+ Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
return this.handlers.registerParser(subobjectType, parser);
}
@Override
public RROSubobjectParser getSubobjectParser(final int subobjectType) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+ Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
return this.handlers.getParser(subobjectType);
}
- @Override
public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
final RROSubobjectSerializer serializer) {
return this.handlers.registerSerializer(subobjectClass, serializer);
* 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.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yangtools.yang.binding.DataContainer;
public final class SimpleTlvHandlerRegistry implements TlvHandlerRegistry {
private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
- @Override
public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
- Preconditions.checkArgument(tlvType >= 0 && tlvType < 65535);
- return handlers.registerParser(tlvType, parser);
+ Preconditions.checkArgument(tlvType >= 0 && tlvType < Util.UNSIGNED_SHORT_MAX_VALUE);
+ return this.handlers.registerParser(tlvType, parser);
}
- @Override
- public TlvParser getTlvParser(final int tlvType) {
- return handlers.getParser(tlvType);
+ public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
+ return this.handlers.registerSerializer(tlvClass, serializer);
}
@Override
- public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
- return handlers.registerSerializer(tlvClass, serializer);
+ public TlvParser getTlvParser(final int tlvType) {
+ return this.handlers.getParser(tlvType);
}
@Override
public TlvSerializer getTlvSerializer(final Tlv tlv) {
- return handlers.getSerializer(tlv.getImplementedInterface());
+ return this.handlers.getSerializer(tlv.getImplementedInterface());
}
}
* 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.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleXROSubobjectHandlerFactory implements XROSubobjectHandlerRegistry {
+public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHandlerRegistry {
private final HandlerRegistry<DataContainer, XROSubobjectParser, XROSubobjectSerializer> handlers = new HandlerRegistry<>();
- @Override
public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+ Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
return this.handlers.registerParser(subobjectType, parser);
}
- @Override
- public XROSubobjectParser getSubobjectParser(final int subobjectType) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
- return this.handlers.getParser(subobjectType);
- }
-
- @Override
public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
final XROSubobjectSerializer serializer) {
return this.handlers.registerSerializer(subobjectClass, serializer);
}
+ @Override
+ public XROSubobjectParser getSubobjectParser(final int subobjectType) {
+ Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
+ return this.handlers.getParser(subobjectType);
+ }
+
@Override
public XROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
return this.handlers.getSerializer(subobject.getImplementedInterface());
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class Main {
+ private static final Logger logger = LoggerFactory.getLogger(Main.class);
+
public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
+ "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+ "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
"With no parameters, this help is printed.";
+ private Main() {
+
+ }
+
public static void main(final String[] args) throws Exception {
if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
System.out.println(Main.usage);
i++;
}
} else {
- System.out.println("WARNING: Unrecognized argument: " + args[i]);
+ logger.warn("WARNING: Unrecognized argument: {}", args[i]);
}
i++;
}
if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * 4) {
- System.out.println("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
+ logger.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
}
if (deadTimerValue == 0) {
deadTimerValue = keepAliveValue * 4;
final OpenObject prefs = spf.getSessionProposal(address, 0);
- final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+ final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
}
@Override
public void onSessionUp(final PCEPSession session) {
logger.debug("Session up.");
- // final List<ExplicitRouteSubobject> subs = new ArrayList<ExplicitRouteSubobject>();
- // subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 10, 1, 1, 2 }), 32),
- // false));
- // subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 2, 2, 2, 2 }), 32),
- // false));
- // final CompositeInstantiationObject cpo = new CompositeInstantiationObject(new
- // PCEPEndPointsObject<IPv4Address>(IPv4.FAMILY.addressForBytes(new byte[] {
- // 1, 1, 1, 1 }), IPv4.FAMILY.addressForBytes(new byte[] { 2, 2, 2, 2 })), new PCEPLspaObject(0, 0, 0, (short)
- // 0, (short) 0, false, false, false, false), new PCEPExplicitRouteObject(subs, false), null, null);
- //
- // session.sendMessage(new PCCreateMessage(Lists.newArrayList(cpo)));
}
@Override
public void onSessionUp(final PCEPSession session) {
logger.debug("Session up.");
this.up = true;
- // this.notifyAll();
}
@Override
public void onSessionDown(final PCEPSession session, final Exception e) {
logger.debug("Session down. Cause : {} or {}", e);
this.up = false;
- // this.notifyAll();
}
@Override
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
-import org.opendaylight.protocol.pcep.impl.SingletonPCEPProviderContext;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.TlvsBuilder;
(short) 30).setDeadTimer((short) 120).setSessionId((short) 0).setTlvs(builder.build()).build(), 0);
final PCCMock<Message, PCEPSessionImpl, PCEPSessionListener> pcc = new PCCMock<>(snf,
- new PCEPHandlerFactory(SingletonPCEPProviderContext.getInstance().getMessageHandlerRegistry()),
+ new PCEPHandlerFactory(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry()),
new DefaultPromise<PCEPSessionImpl>(GlobalEventExecutor.INSTANCE));
pcc.createClient(new InetSocketAddress("127.0.0.3", 12345), new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 2000),
<maven.jar.version>2.4</maven.jar.version>
<maven.shade.version>2.1</maven.shade.version>
<mockito.version>1.9.5</mockito.version>
- <netty.version>4.0.9.Final</netty.version>
+ <netty.version>4.0.10.Final</netty.version>
<nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>
<slf4j.version>1.7.2</slf4j.version>
<surefire.version>2.15</surefire.version>
"The specified instruction is in process of being
executed and cannot be cancelled. Wait for the
execution process to complete.";
+ base cancel-failure;
}
rpc cancel-instruction {
"Instruction ID clashes with an instruction with an
already-queued instruction. Assign a new identifier
or wait for the enqueued instruction to complete.";
+ base submit-failure;
}
identity too-many-instructions {
description
"Instruction queue size exceeded.";
+ base submit-failure;
+ }
+
+ identity unknown-precondition-id {
+ description
+ "One of the instruction IDs specified in the
+ precondition list is unknown.";
+ base submit-failure;
+ }
+
+ identity dead-on-arrival {
+ description
+ "The instruction was submitted after its deadline has
+ passed, or one of its dependencies resolved as
+ non-sunccessful.";
+ base submit-failure;
}
identity instruction-type {
output {
choice result {
case failure {
- leaf failure {
- type identityref {
- base submit-failure;
+ container failure {
+ leaf type {
+ type identityref {
+ base submit-failure;
+ }
+ mandatory true;
+ }
+
+ leaf-list failed-preconditions {
+ when "../type = dead-on-arrival";
+ type instruction-id;
}
}
}
}
}
}
+
+ notification instruction-status-changed {
+ leaf id {
+ description "Instruction identifier.";
+ type instruction-id;
+ mandatory true;
+ }
+
+ leaf status {
+ description "New status of the instruction.";
+ type instruction-status;
+ mandatory true;
+ }
+
+ container details {
+ description
+ "More details about the instruction state.";
+
+ leaf-list unmet-dependencies {
+ when "../../status = cancelled";
+ type instruction-id;
+ }
+ }
+ }
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>programming-impl</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>programming-parent</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>programming-impl</artifactId>
+ <description>Programming Implementation</description>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>programming-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>programming-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-common</artifactId>
+ <version>${netty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ <Private-Package>
+ org.opendaylight.bgpcep.programming.impl,
+ </Private-Package>
+ <Bundle-Activator>org.opendaylight.bgpcep.programming.impl.BundleActivator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <distributionManagement>
+ <site>
+ <id>${project.artifactId}</id>
+ <name>PROGRAMMING-IMPL Module site</name>
+ <url>${basedir}/target/site/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.programming.impl;
+
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timer;
+
+import java.util.concurrent.Executors;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.ProgrammingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class BundleActivator extends AbstractBindingAwareProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class);
+ private RpcRegistration<ProgrammingService> reg;
+ private final Timer timer = new HashedWheelTimer();
+
+ @Override
+ public void onSessionInitiated(final ProviderContext session) {
+ final NotificationProviderService notifs = Preconditions.checkNotNull(session.getSALService(NotificationProviderService.class));
+
+ reg = Preconditions.checkNotNull(session.addRpcImplementation(ProgrammingService.class,
+ new ProgrammingServiceImpl(notifs, Executors.newSingleThreadExecutor(), timer, null)));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.programming.impl;
+
+import io.netty.util.Timeout;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionInput;
+
+import com.google.common.base.Preconditions;
+
+final class Instruction {
+ private final List<Instruction> dependants = new ArrayList<>();
+ private final List<Instruction> dependencies;
+ private final SubmitInstructionInput input;
+ private volatile InstructionStatus status = InstructionStatus.Queued;
+ private Timeout timeout;
+
+ Instruction(final SubmitInstructionInput input, final List<Instruction> dependencies, final Timeout timeout) {
+ this.input = Preconditions.checkNotNull(input);
+ this.dependencies = Preconditions.checkNotNull(dependencies);
+ this.timeout = Preconditions.checkNotNull(timeout);
+ }
+
+ SubmitInstructionInput getInput() {
+ return input;
+ }
+
+ InstructionStatus getStatus() {
+ return status;
+ }
+
+ void setStatus(final InstructionStatus status) {
+ this.status = status;
+ }
+
+ synchronized void cancel() {
+ if (timeout != null) {
+ timeout.cancel();
+ timeout = null;
+ }
+ }
+
+ synchronized void completed() {
+ timeout = null;
+ }
+
+ synchronized void addDependant(final Instruction d) {
+ dependants.add(d);
+ }
+
+ List<Instruction> getDependencies() {
+ return dependencies;
+ }
+
+ List<Instruction> getDependants() {
+ return dependants;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.programming.impl;
+
+import io.netty.util.Timeout;
+import io.netty.util.Timer;
+import io.netty.util.TimerTask;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.FutureListener;
+
+import java.math.BigInteger;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.concurrent.GuardedBy;
+
+import org.opendaylight.bgpcep.programming.spi.ExecutionResult;
+import org.opendaylight.bgpcep.programming.spi.InstructionExecutor;
+import org.opendaylight.bgpcep.programming.spi.InstructionExecutorRegistry;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.CancelInstructionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.CancelInstructionOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.CancelInstructionOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.DeadOnArrival;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.DuplicateInstructionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatusChangedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.ProgrammingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.UncancellableInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.UnknownInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.UnknownPreconditionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.Details;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.DetailsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.failure.Failure;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.failure.FailureBuilder;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Multimap;
+
+final class ProgrammingServiceImpl implements InstructionExecutorRegistry, ProgrammingService {
+ private static final Logger LOG = LoggerFactory.getLogger(ProgrammingServiceImpl.class);
+ private static final BigInteger MILLION = BigInteger.valueOf(1000000);
+
+ private final Map<InstructionId, Instruction> insns = new HashMap<>();
+
+ @GuardedBy("this")
+ private final Deque<Instruction> readyQueue = new ArrayDeque<>();
+
+ @GuardedBy("this")
+ private final Deque<Instruction> deferredQueue = new ArrayDeque<>();
+
+ @GuardedBy("this")
+ private final Multimap<Class<? extends InstructionType>, InstructionExecutor> executors = ArrayListMultimap.create();
+
+ private final NotificationProviderService notifs;
+ private final ExecutorService executor;
+ private final Timer timer;
+ private java.util.concurrent.Future<Void> thread;
+ private ExecutorService exec;
+
+ ProgrammingServiceImpl(final NotificationProviderService notifs, final ExecutorService executor,
+ final Timer timer, final InstructionExecutorRegistry registry) {
+ this.notifs = Preconditions.checkNotNull(notifs);
+ this.executor = Preconditions.checkNotNull(executor);
+ this.timer = Preconditions.checkNotNull(timer);
+ }
+
+ @Override
+ public java.util.concurrent.Future<RpcResult<CancelInstructionOutput>> cancelInstruction(final CancelInstructionInput input) {
+ return executor.submit(new Callable<RpcResult<CancelInstructionOutput>>() {
+ @Override
+ public RpcResult<CancelInstructionOutput> call() {
+ return realCancelInstruction(input);
+ }
+ });
+ }
+
+ @Override
+ public java.util.concurrent.Future<RpcResult<SubmitInstructionOutput>> submitInstruction(final SubmitInstructionInput input) {
+ return executor.submit(new Callable<RpcResult<SubmitInstructionOutput>>() {
+ @Override
+ public RpcResult<SubmitInstructionOutput> call() {
+ return realSubmitInstruction(input);
+ }
+ });
+ }
+
+ @Override
+ public synchronized Registration<InstructionExecutor> registerInstructionExecutor(final Class<? extends InstructionType> type, final InstructionExecutor executor) {
+ Preconditions.checkNotNull(type);
+ Preconditions.checkNotNull(executor);
+
+ executors.put(type, executor);
+
+ /*
+ * Walk the deferred instructions back to front, check if they have
+ * the same type as the executor we have just registered. If they do,
+ * we move them to the head of readyQueue. This approach should retain
+ * submission order of the instructions.
+ */
+ final Iterator<Instruction> it = deferredQueue.descendingIterator();
+ while (it.hasNext()) {
+ final Instruction i = it.next();
+ if (type.equals(i.getInput().getType())) {
+ it.remove();
+ readyQueue.addFirst(i);
+ }
+ }
+
+ notify();
+
+ final Object lock = this;
+ return new Registration<InstructionExecutor>() {
+ @Override
+ public void close() throws Exception {
+ synchronized (lock) {
+ executors.remove(type, executor);
+ }
+ }
+
+ @Override
+ public InstructionExecutor getInstance() {
+ return executor;
+ }
+ };
+ }
+
+ private static final RpcResult<SubmitInstructionOutput> failedSubmit(final Failure f) {
+ return SuccessfulRpcResult.create(
+ new SubmitInstructionOutputBuilder().setResult(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.FailureBuilder()
+ .setFailure(f).build()).build());
+ }
+
+ private synchronized RpcResult<CancelInstructionOutput> realCancelInstruction(final CancelInstructionInput input) {
+ final Instruction i = insns.get(input.getId());
+ if (i == null) {
+ LOG.debug("Instruction {} not present in the graph", input.getId());
+
+ final CancelInstructionOutput out = new CancelInstructionOutputBuilder().setFailure(UnknownInstruction.class).build();
+ return SuccessfulRpcResult.create(out);
+ }
+
+ switch (i.getStatus()) {
+ case Cancelled:
+ case Executing:
+ case Failed:
+ case Successful:
+ case Unknown:
+ LOG.debug("Instruction {} can no longer be cancelled due to status {}", input.getId());
+ return SuccessfulRpcResult.create(
+ new CancelInstructionOutputBuilder().setFailure(UncancellableInstruction.class).build());
+ case Queued:
+ case Scheduled:
+ break;
+ }
+
+ cancelInstruction(i, null);
+ return SuccessfulRpcResult.create(new CancelInstructionOutputBuilder().build());
+ }
+
+ private synchronized RpcResult<SubmitInstructionOutput> realSubmitInstruction(final SubmitInstructionInput input) {
+ final InstructionId id = input.getId();
+ if (insns.get(id) != null) {
+ LOG.info("Instruction ID {} already present", id);
+ return failedSubmit(new FailureBuilder().setType(DuplicateInstructionId.class).build());
+ }
+
+ // First things first: check the deadline
+ final BigInteger now = BigInteger.valueOf(System.currentTimeMillis()).multiply(MILLION);
+ final BigInteger left = input.getDeadline().getValue().subtract(now);
+
+ if (left.compareTo(BigInteger.ZERO) <= 0) {
+ LOG.debug("Instruction {} deadline has already passed by {}ns", id, left);
+ return failedSubmit(new FailureBuilder().setType(DeadOnArrival.class).build());
+ }
+
+ // Resolve dependencies
+ final List<Instruction> dependencies = new ArrayList<>();
+ for (final InstructionId pid : input.getPreconditions()) {
+ final Instruction i = insns.get(pid);
+ if (i == null) {
+ LOG.info("Instruction {} depends on {}, which is not a known instruction", id, pid);
+ return failedSubmit(new FailureBuilder().setType(UnknownPreconditionId.class).build());
+ }
+
+ dependencies.add(i);
+ }
+
+ // Check if all dependencies are non-failed
+ final List<InstructionId> unmet = new ArrayList<>();
+ for (final Instruction d : dependencies) {
+ switch (d.getStatus()) {
+ case Cancelled:
+ case Failed:
+ case Unknown:
+ unmet.add(d.getInput().getId());
+ break;
+ case Executing:
+ case Queued:
+ case Scheduled:
+ case Successful:
+ break;
+ }
+ }
+
+ /*
+ * Some dependencies have failed, declare the request dead-on-arrival
+ * and fail the operation.
+ */
+ if (!unmet.isEmpty()) {
+ return failedSubmit(new FailureBuilder().setType(DeadOnArrival.class).setFailedPreconditions(unmet).build());
+ }
+
+ /*
+ * All pre-flight checks done are at this point, the following
+ * steps can only fail in catastrophic scenarios (OOM and the
+ * like).
+ */
+
+ // Schedule a timeout for the instruction
+ final Timeout t = timer.newTimeout(new TimerTask() {
+ @Override
+ public void run(final Timeout timeout) throws Exception {
+ timeoutInstruction(input.getId());
+ }
+ }, left.longValue(), TimeUnit.NANOSECONDS);
+
+ // Put it into the instruction list
+ final Instruction i = new Instruction(input, dependencies, t);
+ insns.put(id, i);
+
+ // Attach it into its dependencies
+ for (final Instruction d : dependencies) {
+ d.addDependant(i);
+ }
+
+ /*
+ * All done. The next part is checking whether the instruction can
+ * run, which we can figure out after sending out the acknowledgement.
+ * This task should be ingress-weighed, so we reinsert it into the
+ * same execution service.
+ */
+ executor.submit(new Runnable() {
+ @Override
+ public void run() {
+ tryScheduleInstruction(i);
+ }
+ });
+
+ return SuccessfulRpcResult.create(new SubmitInstructionOutputBuilder().build());
+ }
+
+ @GuardedBy("this")
+ private void transitionInstruction(final Instruction v, final InstructionStatus status, final Details details) {
+ // Set the status
+ v.setStatus(status);
+
+ LOG.debug("Instruction {} transitioned to status {}", v.getInput().getId(), status);
+
+ // Send out a notification
+ notifs.publish(new InstructionStatusChangedBuilder().
+ setId(v.getInput().getId()).setStatus(status).setDetails(details).build());
+ }
+
+ @GuardedBy("this")
+ private void cancelSingle(final Instruction i, final Details details) {
+ // Stop the timeout
+ i.cancel();
+
+ // Set the new status and send out notification
+ transitionInstruction(i, InstructionStatus.Cancelled, details);
+ }
+
+ @GuardedBy("this")
+ private void cancelDependants(final Instruction v) {
+ final Details details = new DetailsBuilder().setUnmetDependencies(ImmutableList.of(v.getInput().getId())).build();
+ for (final Instruction d : v.getDependants()) {
+ switch (d.getStatus()) {
+ case Cancelled:
+ case Executing:
+ case Failed:
+ case Successful:
+ case Unknown:
+ break;
+ case Queued:
+ case Scheduled:
+ cancelSingle(d, details);
+ cancelDependants(d);
+ break;
+ }
+ }
+ }
+
+ private synchronized void cancelInstruction(final Instruction i, final Details details) {
+ deferredQueue.remove(i);
+ readyQueue.remove(i);
+ cancelSingle(i, details);
+ cancelDependants(i);
+ }
+
+ private synchronized void timeoutInstruction(final InstructionId id) {
+ final Instruction i = insns.get(id);
+ if (i == null) {
+ LOG.warn("Instruction {} timed out, but not found in the queue", id);
+ return;
+ }
+
+ switch (i.getStatus()) {
+ case Cancelled:
+ case Failed:
+ case Successful:
+ LOG.debug("Instruction {} has status {}, timeout is a no-op", id, i.getStatus());
+ break;
+ case Unknown:
+ LOG.warn("Instruction {} has status {} before timeout completed", id, i.getStatus());
+ break;
+ case Executing:
+ LOG.info("Instruction {} timed out while executing, transitioning into Unknown", id);
+ transitionInstruction(i, InstructionStatus.Unknown, null);
+ cancelDependants(i);
+ break;
+ case Queued:
+ LOG.debug("Instruction {} timed out while Queued, cancelling it", id);
+
+ final List<InstructionId> ids = new ArrayList<>();
+ for (final Instruction d : i.getDependencies()) {
+ if (d.getStatus() != InstructionStatus.Successful) {
+ ids.add(d.getInput().getId());
+ }
+ }
+
+ cancelInstruction(i, new DetailsBuilder().setUnmetDependencies(ids).build());
+ break;
+ case Scheduled:
+ LOG.debug("Instruction {} timed out while Scheduled, cancelling it", i.getInput().getId());
+ // FIXME: we should provide details why it timed out while scheduled
+ cancelInstruction(i, null);
+ break;
+ }
+ }
+
+ @GuardedBy("this")
+ private synchronized void tryScheduleInstruction(final Instruction i) {
+ Preconditions.checkState(i.getStatus().equals(InstructionStatus.Queued));
+
+ /*
+ * Check all vertices we depend on. We start off as ready for
+ * scheduling. If we encounter a cancelled/failed/unknown
+ * dependency, we cancel this instruction (and cascade). If we
+ * encounter an executing/queued/scheduled dependency, we hold
+ * of scheduling this one.
+ */
+ boolean ready = true;
+
+ final List<InstructionId> unmet = new ArrayList<>();
+ for (final Instruction d : i.getDependencies()) {
+ switch (d.getStatus()) {
+ case Cancelled:
+ case Failed:
+ case Unknown:
+ unmet.add(d.getInput().getId());
+ break;
+ case Executing:
+ case Queued:
+ case Scheduled:
+ ready = false;
+ break;
+ case Successful:
+ // No-op
+ break;
+ }
+ }
+
+ if (!unmet.isEmpty()) {
+ LOG.debug("Instruction {} was Queued, while some dependencies were resolved unsuccessfully, cancelling it", i.getInput().getId());
+ cancelSingle(i, new DetailsBuilder().setUnmetDependencies(unmet).build());
+ cancelDependants(i);
+ return;
+ }
+
+ if (ready) {
+ LOG.debug("Instruction {} is ready for execution", i.getInput().getId());
+ transitionInstruction(i, InstructionStatus.Scheduled, null);
+
+ readyQueue.add(i);
+ notify();
+ }
+ }
+
+ private synchronized void executionFailed(final Instruction i, final Throwable cause) {
+ LOG.error("Instruction {} failed to execute", i.getInput().getId(), cause);
+ transitionInstruction(i, InstructionStatus.Failed, null);
+ cancelDependants(i);
+ }
+
+ private synchronized void executionSuccessful(final Instruction i, final ExecutionResult<?> res) {
+ i.cancel();
+
+ transitionInstruction(i, res.getStatus(), res.getDetails());
+
+ // Walk all dependants and try to schedule them
+ for (final Instruction d : i.getDependants()) {
+ tryScheduleInstruction(d);
+ }
+ }
+
+ private synchronized void processQueues() throws InterruptedException {
+ /*
+ * This method is only ever interrupted by InterruptedException
+ */
+ while (true) {
+ while (!readyQueue.isEmpty()) {
+ final Instruction i = readyQueue.poll();
+
+ Preconditions.checkState(i.getStatus().equals(InstructionStatus.Scheduled));
+ final SubmitInstructionInput input = i.getInput();
+
+ /*
+ * Walk all the registered executors for a particular type and
+ * offer them the chance to execute the instruction. The first
+ * one to accept it wins.
+ */
+ Future<ExecutionResult<?>> f = null;
+ final Collection<InstructionExecutor> el = executors.get(input.getType());
+
+ for (final InstructionExecutor e : el) {
+ f = e.offerInstruction(input.getArguments());
+ if (f != null) {
+ break;
+ }
+ }
+
+ // We did not find an executor -- defer the instruction
+ if (f == null) {
+ deferredQueue.add(i);
+ continue;
+ }
+
+ transitionInstruction(i, InstructionStatus.Executing, null);
+ f.addListener(new FutureListener<ExecutionResult<?>>() {
+ @Override
+ public void operationComplete(final Future<ExecutionResult<?>> future) {
+ if (future.isSuccess()) {
+ executionSuccessful(i, future.getNow());
+ } else {
+ executionFailed(i, future.cause());
+ }
+ }
+ });
+ }
+
+ wait();
+ }
+ }
+
+ synchronized void start(final ThreadFactory threadFactory) {
+ Preconditions.checkState(exec == null, "Programming service dispatch thread already started");
+
+ exec = Executors.newSingleThreadExecutor(threadFactory);
+ thread = exec.submit(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ try {
+ processQueues();
+ } catch (Exception ex) {
+ if (!(ex instanceof InterruptedException)) {
+ LOG.error("Programming service dispatch thread died", ex);
+ }
+ throw ex;
+ }
+ return null;
+ }
+ });
+ exec.shutdown();
+ }
+
+ synchronized void stop(final long timeout, final TimeUnit unit) throws InterruptedException {
+ Preconditions.checkState(exec != null, "Programming service dispatch thread already stopped");
+
+ thread.cancel(true);
+ exec.awaitTermination(timeout, unit);
+ exec = null;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.programming.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+final class SuccessfulRpcResult<T> implements RpcResult<T> {
+ private final T value;
+
+ private SuccessfulRpcResult(final T value) {
+ this.value = value;
+ }
+
+ static <T> SuccessfulRpcResult<T> create(final T value) {
+ return new SuccessfulRpcResult<T>(value);
+ }
+
+ @Override
+ public boolean isSuccessful() {
+ return true;
+ }
+
+ @Override
+ public T getResult() {
+ return value;
+ }
+
+ @Override
+ public Collection<RpcError> getErrors() {
+ return Collections.emptyList();
+ }
+}
\ No newline at end of file
<name>${project.artifactId}</name>
<modules>
- <module>api</module>
+ <module>api</module>
+ <module>impl</module>
+ <module>spi</module>
<module>tunnel-api</module>
</modules>
</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>programming-spi</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>programming-parent</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>programming-spi</artifactId>
+ <description>Programming Service Provider Interface</description>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>programming-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-common</artifactId>
+ <version>${netty.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.opendaylight.bgpcep.programming.spi,
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <distributionManagement>
+ <site>
+ <id>${project.artifactId}</id>
+ <name>PROGRAMMING-SPI Module site</name>
+ <url>${basedir}/target/site/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.programming.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.Details;
+
+import com.google.common.base.Preconditions;
+
+public final class ExecutionResult<T extends Details> {
+ private final InstructionStatus status;
+ private final T details;
+
+ public ExecutionResult(final InstructionStatus status, final T details) {
+ Preconditions.checkArgument(
+ status == InstructionStatus.Cancelled ||
+ status == InstructionStatus.Failed ||
+ status == InstructionStatus.Successful, "Illegal instruction status " + status);
+ Preconditions.checkArgument(status != InstructionStatus.Failed || details != null, "Failed status requires details");
+
+ this.status = status;
+ this.details = details;
+ }
+
+ public InstructionStatus getStatus() {
+ return status;
+ }
+
+ public T getDetails() {
+ return details;
+ }
+
+ @Override
+ public String toString() {
+ return "ExecutionResult [status=" + status + ", details=" + details
+ + "]";
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.programming.spi;
+
+import io.netty.util.concurrent.Future;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.input.Arguments;
+
+public interface InstructionExecutor {
+ Future<ExecutionResult<?>> offerInstruction(Arguments arguments);
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.programming.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionType;
+import org.opendaylight.yangtools.concepts.Registration;
+
+public interface InstructionExecutorRegistry {
+ Registration<InstructionExecutor> registerInstructionExecutor(Class<? extends InstructionType> type, InstructionExecutor executor);
+}
namespace "urn:opendaylight:params:xml:ns:yang:topology:tunnel:programming";
prefix "ttp";
- import network-topology { prefix nt; revision-date 2013-07-12; }
+ import network-topology { prefix nt; revision-date 2013-10-21; }
import topology-tunnel { prefix tt; revision-date 2013-08-19; }
import programming { prefix pgm; revision-date 2013-09-30; }
}
}
- grouping generalized-channel-set-label {
- reference "https://tools.ietf.org/html/rfc6002#section-3.2";
-
- uses c-label;
-
- list subobjects {
- uses label-set;
- }
- }
-
//marker
grouping c-subobject {
case waveband-switching-label {
uses waveband-switching-label;
}
- case generalized-channel-set-label {
- uses generalized-channel-set-label;
- }
}
}
description "Subobject of an Explicit Route Object";
reference "https://tools.ietf.org/html/rfc4874#section-4.1";
uses basic-explicit-route-subobjects {
-// augment "subobject-type" {
-// case exrs {
-// container exrs {
-// uses exclude-route-subobjects;
-// }
-// }
-// }
+ augment "subobject-type" {
+ case exrs {
+ list exrs {
+ uses exclude-route-subobjects;
+ }
+ }
+ }
}
}
}
}
organization "TBD";
-
contact "TBD";
description "ISIS Topology model";
- revision "2013-07-12" {
+ revision "2013-10-21" {
description "Initial version";
}
typedef iso-system-id {
description "ISO System ID. RFC 1237";
type string {
- pattern '[0-9a-fA-F]{4}(.[0-9a-fA-F]{4}){2}';
+ pattern '[0-9a-fA-F]{4}(\.[0-9a-fA-F]{4}){2}';
}
}
typedef iso-net-id {
description "ISO NET ID. RFC 1237";
type string {
- pattern '[0-9a-fA-F]{2}((.[0-9a-fA-F]{4}){6}*)';
+ pattern '[0-9a-fA-F]{2}((\.[0-9a-fA-F]{4}){6})';
}
}
}
augment "/nt:network-topology/nt:topology/igp:igp-topology-attributes" {
- when "../../topology-types/isis";
- container isis-topogloy-attributes {
+ when "../nt:topology-types/l3t:l3-unicast-igp-topology/isis";
+ container isis-topology-attributes {
leaf net {
type iso-net-id;
}
}
augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes" {
- when "../../../topology-types/isis";
+ when "../../nt:topology-types/l3t:l3-unicast-igp-topology/isis";
uses isis-node-attributes;
-
}
augment "/nt:network-topology/nt:topology/nt:link/igp:igp-link-attributes" {
- when "../../../../topology-types/isis";
+
+ when "../../nt:topology-types/l3t:l3-unicast-igp-topology/isis";
uses isis-link-attributes;
}
}
container ted {
uses ted:ted-node-attributes;
-
}
}
}
organization "TBD";
contact "TBD";
- revision "2013-07-12" {
+ revision "2013-10-21" {
description "Initial revision";
reference "TBD";
}
base "flag-identity";
}
-
typedef flag-type {
+
type identityref {
base "flag-identity";
}
type flag-type;
}
leaf-list router-id {
-
description "Router-id for the node";
+
type inet:ip-address;
}
list prefix {
case unnumbered {
leaf unnumbered-id {
description "Unnumbered interface identifier";
-
type uint32;
+
}
}
}
}
augment "/nt:network-topology/nt:topology" {
- when "topology-types/l3-unicast-igp-topology";
+ when "nt:topology-types/l3-unicast-igp-topology";
uses igp-topology-attributes;
}
augment "/nt:network-topology/nt:topology/nt:node" {
- when "../../topology-types/l3-unicast-igp-topology";
+ when "../nt:topology-types/l3-unicast-igp-topology";
uses igp-node-attributes;
}
augment "/nt:network-topology/nt:topology/nt:link" {
- when "../../topology-types/l3-unicast-igp-topology";
+ when "../nt:topology-types/l3-unicast-igp-topology";
uses igp-link-attributes;
}
augment "/nt:network-topology/nt:topology/nt:node/nt:termination-point" {
- when "../../topology-types/l3-unicast-igp-topology";
+ when "../../nt:topology-types/l3-unicast-igp-topology";
uses igp-termination-point-attributes;
}
}
leaf topology-ref {
type nt:topology-ref;
-
}
+
uses l3-unicast-igp-topology-type;
uses nt:link-attributes;
uses igp-link-attributes;
through a hierarchy of nodes, then connecting nodes at
upper layers of the hierarchy.";
- revision 2013-07-12 {
+ revision 2013-10-21 {
description
"Initial revision.";
}
and/or the type of topology that the node is a part of.";
}
+
typedef link-id {
type inet:uri;
description
(This type should not be used for relative references.
In such a case, a relative path should be used instead.)";
}
-
typedef topology-ref {
type leafref {
path "/network-topology/topology/topology-id";
path "/network-topology/topology/node/node-id";
}
description
+
"A type for an absolute reference to a node instance.
(This type should not be used for relative references.
In such a case, a relative path should be used instead.)";
in a supporting node.
This dependency information can be inferred from
the dependencies between links. For this reason,
-
this item is not separately configurable. Hence no
corresponding constraint needs to be articulated.
The corresponding information is simply provided by the
The objects are provided in a grouping so that in addition to
the datastore, the data can also be included in notifications
as needed.";
+
leaf node-id {
type node-id;
description
type link-id;
description
"The identifier of a link in the topology.
-
A link is specific to a topology to which it belongs.";
}
container source {
type tp-ref;
description
"Termination point within source node that terminates the link.";
+
}
}
container destination {
list topology {
description "
This is the model of an abstract topology.
- A topology contins nodes and links.
+ A topology contains nodes and links.
Each topology MUST be identified by
unique topology-id for reason that a network could contain many
topologies.
";
key "topology-id";
leaf topology-id {
-
type topology-id;
description "
It is presumed that a datastore will contain many topologies. To
topology identifiers.
";
}
+ leaf server-provided {
+ type boolean;
+ config false;
+ description "
+ Indicates whether the topology is configurable by clients,
+ or whether it is provided by the server. This leaf is
+
+ populated by the server implementing the model.
+ It is set to false for topologies that are created by a client;
+ it is set to true otherwise. If it is set to true, any
+ attempt to edit the topology MUST be rejected.
+ ";
+ }
container topology-types {
description
"This container is used to identify the type, or types
// This constraint is meant to ensure that a referenced node is in fact
// a node in an underlay topology.
list termination-point {
-
description
+
"A termination point can terminate a link.
Depending on the type of topology, a termination point could,
for example, refer to a port or an interface.";
module ospf-topology {
yang-version 1;
- namespace "urn:ietf:params:xml:ns:yang:ospf-topology";
-
+ namespace "urn:TBD:params:xml:ns:yang:ospf-topology";
// replace with IANA namespace when assigned
+
prefix "ospf";
import network-topology {
}
import l3-unicast-igp-topology {
- prefix "igp";
+ prefix "l3t";
}
import ietf-inet-types {
prefix "inet";
contact "TBD";
description "OSPF Topology model";
- revision "2013-07-12" {
+ revision "2013-10-21" {
description "Initial revision";
reference "TBD";
}
}
}
- augment "/nt:network-topology/nt:topology/nt:topology-types/igp:l3-unicast-igp-topology" {
+ augment "/nt:network-topology/nt:topology/nt:topology-types/l3t:l3-unicast-igp-topology" {
uses ospf-topology-type;
}
- augment "/nt:network-topology/nt:topology/igp:igp-topology-attributes" {
- when "../topology-types/ospf";
+ augment "/nt:network-topology/nt:topology/l3t:igp-topology-attributes" {
+ when "../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
container ospf-topology-attributes {
leaf area-id {
type area-id;
}
}
-
}
- augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes" {
- when "../../../topology-types/ospf";
+ augment "/nt:network-topology/nt:topology/nt:node/l3t:igp-node-attributes" {
+ when "../../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
uses ospf-node-attributes;
}
- augment "/nt:network-topology/nt:topology/nt:link/igp:igp-link-attributes" {
- when "../../../topology-types/ospf";
+ augment "/nt:network-topology/nt:topology/nt:link/l3t:igp-link-attributes" {
+ when "../../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
uses ospf-link-attributes;
}
- augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes/igp:prefix" {
- when "../../../../topology-types/ospf";
+ augment "/nt:network-topology/nt:topology/nt:node/l3t:igp-node-attributes/l3t:prefix" {
+ when "../../../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
uses ospf-prefix-attributes;
}
type uint32;
}
leaf-list multi-topology-id {
-
description "List of Multi-Topology Identifier up-to 128 (0-127). RFC 4915";
max-elements "128";
+
type uint8 {
range "0..127";
}
}
} // ospf-link-attributes
-
grouping ospf-prefix-attributes {
container ospf-prefix-attributes {
+
leaf forwarding-address {
- when "../../igp:l3-unicast-igp-topology/igp:ospf/igp:router-type/igp:asbr";
+ when "../../l3t:l3-unicast-igp-topology/l3t:ospf/l3t:router-type/l3t:asbr";
type inet:ipv4-address;
}
}
}
- augment "/igp:igp-node-event" {
+ augment "/l3t:igp-node-event" {
uses ospf-topology-type;
uses ospf:ospf-node-attributes;
}
- augment "/igp:igp-link-event" {
+ augment "/l3t:igp-link-event" {
uses ospf-topology-type;
uses ospf:ospf-link-attributes;
}
- augment "/igp:igp-prefix-event" {
+ augment "/l3t:igp-prefix-event" {
uses ospf-topology-type;
uses ospf:ospf-prefix-attributes;
}
organization "TBD";
contact
"TBD";
-
description
"Helper module to hold TED attributes for OSPF/ISIS";
- revision 2013-07-12 {
+ revision 2013-10-21 {
+
description
"Initial revision";
}
enum "LSC" {
description
"Lambda-Switch Capable (LSC)";
-
value 150;
}
enum "FSC" {
description
+
"Fiber-Switch Capable (FSC)";
value 200;
}
}
grouping ted-node-attributes {
-
description
"Identifier to uniquely identify a node in TED";
reference "RFC 5305, RFC 6119: IPv6 Traffic Engineering in IS-IS/OSPF";
leaf te-router-id-ipv4 {
+
description
"Globally unique IPv4 Traffic Engineering Router ID.";
type inet:ipv4-address;
}
}
-
grouping ted-link-attributes {
description
"TED Attributes associated with the link.";
reference "RFC 3630, RFC 3784: IS-IS / OSPF Traffic Engineering (TE)";
+
leaf color {
description
"Administrative group or color of the link";
}
container srlg {
description
-
"Shared Risk Link Group Attributes";
uses srlg-attributes;
}
description
"Interface has packet-switching capabilities";
leaf minimum-lsp-bandwidth {
-
description
"Minimum LSP Bandwidth. Units in bytes per second";
type decimal64 {
fraction-digits 2;
}
+
}
leaf interface-mtu {
description
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>topology-pcep-api</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>topology-parent</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>topology-pcep-api</artifactId>
+ <description>Topology PCEP API</description>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>pcep-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-binding</artifactId>
+ <version>${yang.binding.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ <version>${yangtools.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller.model</groupId>
+ <artifactId>model-inventory</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <version>${yangtools.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-sources</goal>
+ </goals>
+ <configuration>
+ <yangFilesRootDir>src/main/yang</yangFilesRootDir>
+ <codeGenerators>
+ <generator>
+ <codeGeneratorClass>
+ org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+ </codeGeneratorClass>
+ <outputBaseDir>
+ target/generated-sources/sal
+ </outputBaseDir>
+ </generator>
+ </codeGenerators>
+ <inspectDependencies>true</inspectDependencies>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>maven-sal-api-gen-plugin</artifactId>
+ <version>${yang.binding.version}</version>
+ <type>jar</type>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024,
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <distributionManagement>
+ <site>
+ <id>${project.artifactId}</id>
+ <name>TOPOLOGY-PCEP-API Module site</name>
+ <url>${basedir}/target/site/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+</project>
--- /dev/null
+module inventory-pcep {
+ // vi: set et smarttab sw=4 tabstop=4:
+ yang-version 1;
+ namespace "urn:opendaylight:inventory:pcep";
+ prefix "inv-pcep";
+
+ import network-topology { prefix nt; revision-date 2013-10-21; }
+ import opendaylight-inventory { prefix inv; revision-date 2013-08-19; }
+ import pcep-types { prefix pcep; revision-date 2013-10-05; }
+
+ organization "Cisco Systems, Inc.";
+ contact "Robert Varga <rovarga@cisco.com>";
+
+ description
+ "This module contains the PCEP extensions to base inventory
+ model.
+
+ Copyright (c)2013 Cisco Systems, Inc. All rights reserved.";
+
+ revision "2013-10-24" {
+ description
+ "Initial revision.";
+ reference "";
+ }
+
+ typedef pcc-sync-state {
+ type enumeration {
+ enum initial-resync {
+ description
+ "Initial state resynchronization is being performed.";
+ }
+ enum synchronized {
+ description
+ "State synchronization has been achieved.";
+ }
+ }
+ }
+
+ augment "/inv:nodes/inv:node" {
+ container path-computation-client {
+ description
+ "PCC-related run-time information. This container is only
+ present when the node is connected through PCEP in a PCC
+ role.";
+
+ container stateful-tlv {
+ uses pcep:stateful-capability-tlv;
+ }
+
+ leaf state-sync {
+ when "../stateful-tlv";
+ type pcc-sync-state;
+ }
+
+ leaf topology-node {
+ type nt:node-ref;
+ }
+ }
+ }
+}
+
--- /dev/null
+module network-topology-pcep {
+ // vi: set et smarttab sw=4 tabstop=4:
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:topology:pcep";
+ prefix "pn";
+
+ import network-topology { prefix nt; revision-date 2013-10-21; }
+ import pcep-types { prefix pcep; revision-date 2013-10-05; }
+
+ organization "Cisco Systems, Inc.";
+ contact "Robert Varga <rovarga@cisco.com>";
+
+ description
+ "This module contains the PCEP extensions to base topology model. It
+ exposes the LSPs for which a particular node is the head end.
+
+ Copyright (c)2013 Cisco Systems, Inc. All rights reserved.";
+
+ revision "2013-10-24" {
+ description
+ "Initial revision.";
+ reference "";
+ }
+
+ grouping pcep-client-attributes {
+ description "Data present in a node which is a PCEP client (PCC).";
+
+ container pcc {
+ config false;
+
+ list lsps {
+ leaf name {
+ type pcep:symbolic-path-name;
+ }
+ key name;
+
+ // FIXME: hide protocol-specific?
+ uses pcep:lsp-object;
+ }
+ }
+ }
+
+ augment "/nt:network-topology/nt:topology/nt:node" {
+ uses pcep-client-attributes;
+ }
+}
+
<name>${project.artifactId}</name>
<modules>
- <module>api</module>
+ <module>api</module>
+ <module>pcep-api</module>
+ <module>provider-bgp</module>
+ <module>provider-pcep</module>
<module>tunnel-api</module>
- <module>tunnel-pcep</module>
+ <module>tunnel-pcep-api</module>
+ <module>tunnel-provider-pcep</module>
<module>segment-routing</module>
</modules>
</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>topology-provider-bgp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>topology-parent</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>topology-provider-bgp</artifactId>
+ <description>BGP Topology Provider</description>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>bgp-rib-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>bgp-linkstate</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.opendaylight.bgpcep.topology.provider.bgp
+ </Export-Package>
+ <Private-Package>
+ org.opendaylight.bgpcep.topology.provider.bgp.impl
+ </Private-Package>
+ <Bundle-Activator>org.opendaylight.bgpcep.topology.provider.bgp.impl.Activator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <distributionManagement>
+ <site>
+ <id>${project.artifactId}</id>
+ <name>TOPOLOGY-PROVIDER-BGP Module site</name>
+ <url>${basedir}/target/site/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.provider.bgp;
+
+import java.util.EventListener;
+
+import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.DataModification;
+
+public interface LocRIBListener extends EventListener {
+ /**
+ * @param trans Modification transaction. The implementation must explicitly commit
+ * it if it wishes to have its modifications propagated. The transaction
+ * is not shared with any other entity and will be cleaned up by the
+ * caller if it is not committed before this method returns.
+ * @param event Data change event
+ * @throws Exception throw it if you must. If you can handle it, please do so.
+ */
+ public void onLocRIBChange(DataModification<?, ?> trans, DataChangeEvent<?, ?> event) throws Exception;
+}
--- /dev/null
+package org.opendaylight.bgpcep.topology.provider.bgp;
+
+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.SubsequentAddressFamily;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public final class LocRIBListeners {
+ public interface Subscribtion {
+ public Class<? extends AddressFamily> getAfi();
+ public Class<? extends SubsequentAddressFamily> getSafi();
+ public LocRIBListener getLocRIBListener();
+ }
+
+ private LocRIBListeners() {
+
+ }
+
+ public static ServiceRegistration<Subscribtion> subscribe(final BundleContext context,
+ final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final LocRIBListener listener) {
+ return context.registerService(Subscribtion.class,
+ new Subscribtion() {
+ @Override
+ public Class<? extends AddressFamily> getAfi() {
+ return afi;
+ }
+
+ @Override
+ public Class<? extends SubsequentAddressFamily> getSafi() {
+ return safi;
+ }
+
+ @Override
+ public LocRIBListener getLocRIBListener() {
+ return listener;
+ }
+ }, null);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.provider.bgp.impl;
+
+import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListeners;
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import com.google.common.base.Preconditions;
+
+public class Activator extends AbstractBindingAwareProvider {
+// private ServiceRegistration<LocRIBListeners.Subscribtion> ipv4, ipv6, linkstate;
+ private BundleContext context;
+
+ @Override
+ public void onSessionInitiated(final ProviderContext session) {
+ final LocRIBListenerSubscriptionTracker reg = new LocRIBListenerSubscriptionTracker(context, session.getSALService(DataProviderService.class));
+ reg.open();
+
+// ipv4 = LocRIBListeners.subscribe(context, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4ReachabilityTopologyBuilder());
+// ipv6 = LocRIBListeners.subscribe(context, Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6ReachabilityTopologyBuilder());
+// linkstate = LocRIBListeners.subscribe(context, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateTopologyBuilder());
+ }
+
+ @Override
+ protected void startImpl(final BundleContext context) {
+ this.context = Preconditions.checkNotNull(context);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.provider.bgp.impl;
+
+import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListener;
+import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListeners;
+import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.DataModification;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.LocRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+final class LocRIBListenerSubscriptionTracker extends ServiceTracker<LocRIBListeners.Subscribtion, ListenerRegistration<LocRIBListener>> {
+ private static final InstanceIdentifier<LocRib> locRIBPath = InstanceIdentifier.builder().node(LocRib.class).toInstance();
+ private static final Logger LOG = LoggerFactory.getLogger(LocRIBListenerSubscriptionTracker.class);
+ private final DataProviderService dps;
+
+ LocRIBListenerSubscriptionTracker(final BundleContext context, final DataProviderService dps) {
+ super(context, LocRIBListeners.Subscribtion.class, null);
+ this.dps = Preconditions.checkNotNull(dps);
+ }
+
+ @Override
+ public ListenerRegistration<LocRIBListener> addingService(final ServiceReference<LocRIBListeners.Subscribtion> reference) {
+ final LocRIBListeners.Subscribtion service = context.getService(reference);
+ if (service == null) {
+ LOG.trace("Service for reference {} disappeared", reference);
+ return null;
+ }
+
+ final InstanceIdentifier<Tables> path = InstanceIdentifier.builder(locRIBPath).
+ node(Tables.class, new TablesKey(service.getAfi(), service.getSafi())).toInstance();
+ final LocRIBListener listener = service.getLocRIBListener();
+
+ final DataChangeListener dcl = new DataChangeListener() {
+
+ @Override
+ public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ final DataModification<?, ?> trans = dps.beginTransaction();
+
+ try {
+ listener.onLocRIBChange(trans, change);
+ } catch (Exception e) {
+ LOG.info("Data change {} was not completely propagated to listener {}", change, listener, e);
+ }
+
+ // FIXME: abort the transaction if it's not committing
+ }
+ };
+
+ final ListenerRegistration<DataChangeListener> reg = dps.registerDataChangeListener(path, dcl);
+
+ return new ListenerRegistration<LocRIBListener>() {
+ @Override
+ public void close() throws Exception {
+ reg.close();
+ }
+
+ @Override
+ public LocRIBListener getInstance() {
+ return listener;
+ }
+ };
+ }
+
+ @Override
+ public void removedService(final ServiceReference<LocRIBListeners.Subscribtion> reference, final ListenerRegistration<LocRIBListener> service) {
+ try {
+ service.close();
+ } catch (Exception e) {
+ LOG.error("Failed to unregister service {}", e);
+ }
+ context.ungetService(reference);
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>topology-provider-pcep</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>topology-parent</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>topology-provider-pcep</artifactId>
+ <description>PCEP Topology Provider</description>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>pcep-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-pcep-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- FIXME: integrate with config to get rid of this -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>pcep-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>pcep-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ <Private-Package>
+ org.opendaylight.bgpcep.topology.provider.pcep
+ </Private-Package>
+ <Bundle-Activator>org.opendaylight.bgpcep.topology.provider.pcep.BundleActivator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <distributionManagement>
+ <site>
+ <id>${project.artifactId}</id>
+ <name>TOPOLOGY-PROVIDER-PCEP Module site</name>
+ <url>${basedir}/target/site/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.provider.pcep;
+
+import io.netty.channel.ChannelFuture;
+import io.netty.util.HashedWheelTimer;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutionException;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.protocol.pcep.PCEPDispatcher;
+import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
+import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
+import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
+import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class BundleActivator extends AbstractBindingAwareProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class);
+
+ @Override
+ public void onSessionInitiated(final ProviderContext session) {
+ final DataProviderService dps = Preconditions.checkNotNull(session.getSALService(DataProviderService.class));
+
+ // FIXME: integration with config subsystem should allow this to be injected as a service
+ final InetSocketAddress address = new InetSocketAddress("0.0.0.0", 4189);
+ final PCEPSessionProposalFactory spf = new PCEPSessionProposalFactoryImpl(30, 10, true, true, true, true, 0);
+ final OpenObject prefs = spf.getSessionProposal(address, 0);
+ final PCEPDispatcher dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(),
+ new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+ final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder().node(Topology.class).toInstance();
+
+ final TopologyExporter exp = new TopologyExporter(dispatcher, dps, topology);
+ final ChannelFuture s = exp.startServer(address);
+ try {
+ s.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to instantiate server", e);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.provider.pcep;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.protocol.framework.SessionListenerFactory;
+import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.PCEPTerminationReason;
+import org.opendaylight.protocol.pcep.TerminationReason;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.PccSyncState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.nodes.node.PathComputationClientBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.nodes.node.path.computation.client.StatefulTlvBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrptMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PlspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.Reports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.reports.Lsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PccBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.pcc.Lsps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.pcc.LspsKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ *
+ */
+final class ServerSessionManager implements SessionListenerFactory<PCEPSessionListener> {
+ private static String createNodeId(final InetAddress addr) {
+ return "pcc://" + addr.getHostAddress();
+ }
+
+ private final class SessionListener implements PCEPSessionListener {
+ private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node inventoryNode(final DataModificationTransaction trans, final InetAddress address) {
+ final String pccId = createNodeId(address);
+
+ // FIXME: after 0.6 yangtools, this cast should not be needed
+ final Nodes nodes = (Nodes)trans.readOperationalData(inventory);
+
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node n : nodes.getNode()) {
+ LOG.debug("Matching inventory node {} to peer {}", n, address);
+ if (n.getId().getValue().equals(pccId)) {
+ return n;
+ }
+
+ // FIXME: locate the node by its management IP address
+ }
+
+ /*
+ * We failed to find a matching node. Let's create a dynamic one
+ * to have a backer. Note that this node will be created in the
+ * Runtime data space.
+ */
+ LOG.debug("Failed to find inventory node for peer {}, creating a new one at {}", address, pccId);
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId id =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId(pccId);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nk =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey(id);
+ final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nii =
+ InstanceIdentifier.builder(inventory).node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, nk).toInstance();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node ret =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder().setId(id).setKey(nk).build();
+
+ trans.putRuntimeData(nii, ret);
+ ownsInventory = true;
+ inventoryNodeId = nii;
+ return ret;
+ }
+
+ final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node topologyNode(
+ final DataModificationTransaction trans,
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node invNode) {
+ // FIXME: after 0.6 yangtools, this cast should not be needed
+ final Topology topo = (Topology)trans.readOperationalData(topology);
+
+ for (final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node n : topo.getNode()) {
+ LOG.debug("Matching topology node {} to inventory node {}", n, invNode);
+ if (n.getNodeId().getValue().equals(invNode.getId().getValue())) {
+ return n;
+ }
+ }
+
+ /*
+ * We failed to find a matching node. Let's create a dynamic one
+ * and note that we are the owner (so we clean it up afterwards).
+ */
+ final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId id =
+ new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId(invNode.getId().getValue());
+ final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey nk =
+ new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey(id);
+ final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> nti =
+ InstanceIdentifier.builder(topology).node(
+ org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, nk).toInstance();
+
+ final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node ret =
+ new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder().
+ setKey(nk).setNodeId(id).build();
+
+ trans.putRuntimeData(nti, ret);
+ ownsTopology = true;
+ topologyNodeId = nti;
+ return ret;
+ }
+
+ @Override
+ public void onSessionUp(final PCEPSession session) {
+ /*
+ * The session went up. Look up the router in Inventory model,
+ * create it if it is not there (marking that fact for later
+ * deletion), and mark it as synchronizing. Also create it in
+ * the topology model, with empty LSP list.
+ */
+ final InetAddress peerAddress = session.getRemoteAddress();
+ final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node invNode = inventoryNode(trans, peerAddress);
+ LOG.debug("Peer {} resolved to inventory node {}", peerAddress, invNode);
+
+ final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node topoNode = topologyNode(trans, invNode);
+ LOG.debug("Peer {} resolved to topology node {}", peerAddress, topoNode);
+
+ // Our augmentation in the topology node
+ final PccBuilder pb = new PccBuilder();
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1 topoAugment =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1Builder().setPcc(pb.build()).build();
+ topologyAugmentId = InstanceIdentifier.builder(topologyNodeId).node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1.class).toInstance();
+ trans.putRuntimeData(topologyAugmentId, topoAugment);
+
+ // Our augmentation in the inventory node
+ pccBuilder = new PathComputationClientBuilder();
+
+ final Tlvs tlvs = session.getRemoteTlvs();
+ final Stateful stateful = tlvs.getStateful();
+ if (stateful != null) {
+ // FIXME: rework once groupings can be used in builders
+ pccBuilder.setStatefulTlv(new StatefulTlvBuilder().setFlags(tlvs.getStateful().getFlags()).build());
+ pccBuilder.setStateSync(PccSyncState.InitialResync);
+ }
+
+ pccBuilder.setTopologyNode(topoNode.getNodeId());
+
+ inventoryAugmentBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1Builder()
+ .setPathComputationClient(pccBuilder.build());
+ inventoryAugmentId = InstanceIdentifier.builder(inventoryNodeId).node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1.class).toInstance();
+ trans.putRuntimeData(inventoryAugmentId, inventoryAugmentBuilder.build());
+
+ // All set, commit the modifications
+ final Future<RpcResult<TransactionStatus>> s = trans.commit();
+
+ /*
+ * FIXME: once this Future is listenable, attach to it so we can
+ * do cleanup if the commit fails. For now we force a commit.
+ */
+ try {
+ s.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to update internal state for session {}, terminating it", session, e);
+ session.close(TerminationReason.Unknown);
+ }
+
+ LOG.info("Session with {} attached to inventory node {} and topology node {}", session.getRemoteAddress(), invNode.getId(), topoNode.getNodeId());
+ }
+
+ private void tearDown(final PCEPSession session) {
+ final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+ /*
+ * The session went down. Undo all the Inventory and Topology
+ * changes we have done.
+ */
+ trans.removeRuntimeData(inventoryAugmentId);
+ if (ownsInventory) {
+ trans.removeRuntimeData(inventoryNodeId);
+ }
+ trans.removeRuntimeData(topologyAugmentId);
+ if (ownsTopology) {
+ trans.removeRuntimeData(topologyNodeId);
+ }
+
+ /*
+ * FIXME: once this Future is listenable, attach to it so we can
+ * do cleanup if the commit fails. For now we force a commit.
+ */
+ final Future<RpcResult<TransactionStatus>> s = trans.commit();
+ try {
+ s.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to cleanup internal state for session {}", session, e);
+ }
+ }
+
+ @Override
+ public void onSessionDown(final PCEPSession session, final Exception e) {
+ LOG.warn("Session {} went down unexpectedly", e);
+ tearDown(session);
+ }
+
+ @Override
+ public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason reason) {
+ LOG.info("Session {} terminated by peer with reason {}", session, reason);
+ tearDown(session);
+ }
+
+ private InstanceIdentifier<Lsps> lspIdentifier(final SymbolicPathName name) {
+ return InstanceIdentifier.builder(topologyAugmentId).
+ node(Lsps.class, new LspsKey(name.getPathName())).toInstance();
+ }
+
+ @Override
+ public void onMessage(final PCEPSession session, final Message message) {
+ if (!(message instanceof PcrptMessage)) {
+ LOG.info("Unhandled message {} on session {}", message, session);
+ session.sendMessage(unhandledMessageError);
+ }
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessage rpt =
+ ((PcrptMessage)message).getPcrptMessage();
+
+ final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+ for (final Reports r : rpt.getReports()) {
+ final Lsp lsp = r.getLsp();
+
+ if (lsp.isSync() && !synced) {
+ // Update synchronization flag
+ synced = true;
+ inventoryAugmentBuilder.setPathComputationClient(pccBuilder.setStateSync(PccSyncState.Synchronized).build());
+ trans.putRuntimeData(inventoryAugmentId, inventoryAugmentBuilder.build());
+ LOG.debug("Session {} achieved synchronized state", session);
+ }
+
+ final PlspId id = lsp.getPlspId();
+ if (lsp.isRemove()) {
+ final SymbolicPathName name = lsps.remove(id);
+ if (name != null) {
+ trans.removeRuntimeData(lspIdentifier(name));
+ }
+
+ LOG.debug("LSP {} removed", lsp);
+ } else {
+ if (!lsps.containsKey(id)) {
+ LOG.debug("PLSPID {} not known yet, looking for a symbolic name", id);
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.Tlvs tlvs =
+ r.getLsp().getTlvs();
+ final SymbolicPathName name = tlvs.getSymbolicPathName();
+ if (name == null) {
+ LOG.error("PLSPID {} seen for the first time, not reporting the LSP");
+ // TODO: what should we do here?
+ continue;
+ }
+ }
+
+ final SymbolicPathName name = lsps.get(id);
+ trans.putRuntimeData(lspIdentifier(name), lsp);
+
+ LOG.debug("LSP {} updated");
+ }
+ }
+
+ /*
+ * FIXME: once this Future is listenable, attach to it so we can
+ * do cleanup if the commit fails. For now we force a commit.
+ */
+ final Future<RpcResult<TransactionStatus>> s = trans.commit();
+ try {
+ s.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to update internal state for session {}, closing it", session, e);
+ session.close(TerminationReason.Unknown);
+ }
+ }
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(ServerSessionManager.class);
+ private static final Pcerr unhandledMessageError = new PcerrBuilder().setPcerrMessage(
+ new PcerrMessageBuilder().setErrorType(null).build()).build();
+ private final Map<PlspId, SymbolicPathName> lsps = new HashMap<>();
+ private final InstanceIdentifier<Nodes> inventory;
+ private final InstanceIdentifier<Topology> topology;
+ private final DataProviderService dataProvider;
+
+ private boolean ownsInventory = false;
+ private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> inventoryNodeId;
+ private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1> inventoryAugmentId;
+ private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1Builder inventoryAugmentBuilder;
+ private PathComputationClientBuilder pccBuilder;
+ private boolean synced = false;
+
+ private boolean ownsTopology = false;
+ private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> topologyNodeId;
+ private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1> topologyAugmentId;
+
+ public ServerSessionManager(final DataProviderService dataProvider,
+ final InstanceIdentifier<Nodes> inventory, final InstanceIdentifier<Topology> topology) {
+ this.dataProvider = Preconditions.checkNotNull(dataProvider);
+ this.inventory = Preconditions.checkNotNull(inventory);
+ this.topology = Preconditions.checkNotNull(topology);
+ }
+
+ @Override
+ public PCEPSessionListener getSessionListener() {
+ return new SessionListener();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.provider.pcep;
+
+import io.netty.channel.ChannelFuture;
+
+import java.net.InetSocketAddress;
+
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.protocol.pcep.PCEPDispatcher;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Preconditions;
+
+public final class TopologyExporter {
+ private static final InstanceIdentifier<Nodes> inventory = new InstanceIdentifier<Nodes>(Nodes.class);
+ private final PCEPDispatcher dispatcher;
+ private final DataProviderService dataProvider;
+ private final InstanceIdentifier<Topology> topology;
+
+ public TopologyExporter(final PCEPDispatcher dispatcher,
+ final DataProviderService dataService,
+ final InstanceIdentifier<Topology> topology) {
+ this.dispatcher = Preconditions.checkNotNull(dispatcher);
+ this.dataProvider = Preconditions.checkNotNull(dataService);
+ this.topology = Preconditions.checkNotNull(topology);
+ }
+
+ public ChannelFuture startServer(final InetSocketAddress address) {
+ return dispatcher.createServer(address, new ServerSessionManager(dataProvider, inventory, topology));
+ }
+}
namespace "urn:opendaylight:params:xml:ns:yang:topology:sr";
prefix "sr";
- import network-topology { prefix nt; revision-date 2013-07-12; }
+ import network-topology { prefix nt; revision-date 2013-10-21; }
organization "Cisco Systems, Inc.";
contact "Robert Varga <rovarga@cisco.com>";
prefix "tun-sr";
import network-topology-sr { prefix sr; revision-date 2013-08-19; }
- import network-topology { prefix nt; revision-date 2013-07-12; }
+ import network-topology { prefix nt; revision-date 2013-10-21; }
import topology-tunnel { prefix tt; revision-date 2013-08-19; }
import topology-tunnel-p2p { prefix p2p; revision-date 2013-08-19; }
namespace "urn:opendaylight:params:xml:ns:yang:topology:tunnel:p2p";
prefix "p2p";
- import network-topology { prefix nt; revision-date 2013-07-12; }
+ import network-topology { prefix nt; revision-date 2013-10-21; }
import topology-tunnel { prefix tt; revision-date 2013-08-19; }
organization "Cisco Systems, Inc.";
prefix "tt";
import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
- import network-topology { prefix nt; revision-date 2013-07-12; }
+ import network-topology { prefix nt; revision-date 2013-10-21; }
organization "Cisco Systems, Inc.";
contact "Robert Varga <rovarga@cisco.com>";
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>topology-tunnel-pcep</artifactId>
+ <artifactId>topology-tunnel-pcep-api</artifactId>
<description>Topology Tunnel PCEP binding</description>
<packaging>bundle</packaging>
<name>${project.artifactId}</name>
<instructions>
<Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
<Export-Package>
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820.*,
</Export-Package>
</instructions>
</configuration>
module topology-tunnel-pcep {
+ // vi: set et smarttab sw=4 tabstop=4:
yang-version 1;
namespace "urn:opendaylight:params:xml:ns:yang:topology:tunnel:pcep";
prefix "pceptun";
import ieee754 { prefix ieee754; revision-date 2013-08-19; }
- import network-topology { prefix nt; revision-date 2013-07-12; }
+ import network-topology { prefix nt; revision-date 2013-10-21; }
import pcep-types { prefix pcep; revision-date 2013-10-05; }
import rsvp { prefix rsvp; revision-date 2013-08-20; }
import topology-tunnel { prefix tt; revision-date 2013-08-19; }
contact "Robert Varga <rovarga@cisco.com>";
description
- "This module contains the Segment Routing extensions to
- base tunnel topology model.
+ "This module contains the PCEP extensions to base tunnel
+ topology model.
Copyright (c)2013 Cisco Systems, Inc. All rights reserved.";
reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3";
}
- typedef operational-status {
- type enumeration {
- enum down;
- enum up;
- enum active;
- enum going-down;
- enum going-up;
- }
- reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3";
- }
-
grouping tunnel-pcep-type {
container pcep-tunnel {
presence "indicates a link is a PCEP tunnel";
}
leaf operational-status {
- type operational-status;
+ type pcep:operational-status;
config false;
}
}
leaf operational-status {
- type operational-status;
+ type pcep:operational-status;
config false;
}
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>topology-tunnel-provider-pcep</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>topology-parent</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>topology-tunnel-provider-pcep</artifactId>
+ <description>PCEP Topology Provider</description>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-pcep-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-tunnel-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topology-tunnel-pcep-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ <Private-Package>
+ org.opendaylight.bgpcep.topology.tunnel.provider.pcep
+ </Private-Package>
+ <Bundle-Activator>org.opendaylight.bgpcep.topology.tunnel.provider.pcep.BundleActivator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <distributionManagement>
+ <site>
+ <id>${project.artifactId}</id>
+ <name>TOPOLOGY-PROVIDER-PCEP Module site</name>
+ <url>${basedir}/target/site/${project.artifactId}</url>
+ </site>
+ </distributionManagement>
+
+</project>
--- /dev/null
+package org.opendaylight.bgpcep.topology.tunnel.provider.pcep;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class BundleActivator extends AbstractBindingAwareProvider {
+ private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class);
+
+ @Override
+ public void onSessionInitiated(final ProviderContext session) {
+ final DataProviderService dps = Preconditions.checkNotNull(session.getSALService(DataProviderService.class));
+
+ // FIXME: migrate to config subsystem
+ final TunnelTopologyExporter tte = new TunnelTopologyExporter(dps, null);
+ tte.addTargetTopology(null);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.tunnel.provider.pcep;
+
+import java.util.Map.Entry;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.pcc.Lsps;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+final class NodeChangedListener implements DataChangeListener {
+ private static final Logger LOG = LoggerFactory.getLogger(NodeChangedListener.class);
+ private final InstanceIdentifier<Topology> target;
+ private final DataProviderService dataProvider;
+
+ NodeChangedListener(final DataProviderService dataProvider, final InstanceIdentifier<Topology> target) {
+ this.dataProvider = Preconditions.checkNotNull(dataProvider);
+ this.target = Preconditions.checkNotNull(target);
+ }
+
+ private void remove(final DataModificationTransaction trans, final InstanceIdentifier<?> id) {
+ if (Node.class.equals(id.getTargetType())) {
+ // FIXME: implement this
+ } else if (Lsps.class.equals(id.getTargetType())) {
+ // FIXME: implement this
+ } else {
+ LOG.debug("Ignoring changed instance {}", id);
+ }
+ }
+
+ private void create(final DataModificationTransaction trans, final InstanceIdentifier<?> id, final DataObject obj) {
+ // FIXME: implement this
+ }
+
+ @Override
+ public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+ for (final InstanceIdentifier<?> i : change.getRemovedOperationalData()) {
+ remove(trans, i);
+ }
+
+ for (final Entry<InstanceIdentifier<?>, DataObject> e : change.getUpdatedOperationalData().entrySet()) {
+ remove(trans, e.getKey());
+ create(trans, e.getKey(), e.getValue());
+ }
+
+ for (final Entry<InstanceIdentifier<?>, DataObject> e : change.getCreatedOperationalData().entrySet()) {
+ create(trans, e.getKey(), e.getValue());
+ }
+
+ final Future<RpcResult<TransactionStatus>> f = trans.commit();
+
+ // FIXME: change to a subscribtion once that is possible
+ try {
+ f.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to propagate a topology change, target topology became inconsistent", e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2013 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.bgpcep.topology.tunnel.provider.pcep;
+
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Preconditions;
+
+final class TunnelTopologyExporter {
+ private final DataProviderService dataProvider;
+ private final InstanceIdentifier<Node> srcTree;
+
+ TunnelTopologyExporter(final DataProviderService dataProvider, final InstanceIdentifier<Topology> sourceTopology) {
+ this.dataProvider = Preconditions.checkNotNull(dataProvider);
+ srcTree = Preconditions.checkNotNull(InstanceIdentifier.builder(sourceTopology).node(Node.class).toInstance());
+ }
+
+ ListenerRegistration<?> addTargetTopology(final InstanceIdentifier<Topology> tunnelTopology) {
+ return dataProvider.registerDataChangeListener(srcTree, new NodeChangedListener(dataProvider, tunnelTopology));
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import com.google.common.base.Objects.ToStringHelper;
-
-/**
- * Extension of the TypesafeContainer which supports the notion of a default
- * key.
- *
- * @param <S> Supertype of all objects stored in this container
- */
-public class DefaultingTypesafeContainer<S> extends TypesafeContainer<S> {
- private static final long serialVersionUID = 140170613440644179L;
- private Class<? extends S> defaultKey = null;
-
- /**
- * Returns the default entry.
- *
- * @return Default entry, or null if no default was set
- */
- public S getDefaultEntry() {
- if (defaultKey == null) {
- return null;
- }
- return defaultKey.cast(getEntry(defaultKey));
- }
-
- /**
- * Sets or resets the default entry.
- *
- * @param entry Default entry value. Use null to reset the container
- * to no default entry.
- */
- public void setDefaultEntry(final S entry) {
- if (defaultKey != null) {
- removeEntry(defaultKey);
- defaultKey = null;
- }
- if (entry != null) {
- /*
- * This is rather obvious: entry is required to be a subclass
- * of T. This implies that its class conforms to
- * Class<? extends T>. For some reason, the compiler is not
- * smart enough to know this.
- */
- @SuppressWarnings("unchecked")
- final Class<? extends S> c = (Class<? extends S>) entry.getClass();
- defaultKey = c;
-
- setEntry(defaultKey, entry);
- }
- }
-
- @Override
- protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
- toStringHelper.add("defaultKey", this.defaultKey);
- return super.addToStringAttributes(toStringHelper);
- }
-
- @Override
- public int hashCode() {
- return super.hashCode() * 7 + (defaultKey != null ? defaultKey.hashCode() : 0);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof DefaultingTypesafeContainer == false) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (super.equals(obj)==false) {
- return false;
- }
- Object thatDefaultKey = ((DefaultingTypesafeContainer<?>)obj).defaultKey;
- if (defaultKey == thatDefaultKey) {
- return true;
- }
- if ((defaultKey == null) != (thatDefaultKey == null)) {
- return false;
- }
- return thatDefaultKey.equals(thatDefaultKey);
- }
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.util;
+
+public class Util {
+
+ public static final int UNSIGNED_SHORT_MAX_VALUE = 65535;
+
+ public static final int UNSIGNED_BYTE_MAX_VALUE = 255;
+
+ public static final int BYTE_MAX_VALUE_BYTES = 0xFF;
+}