Merge "Rework build to move the parent out"
authorDana Kutenicsova <dkutenic@cisco.com>
Sun, 1 Dec 2013 11:59:05 +0000 (11:59 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sun, 1 Dec 2013 11:59:05 +0000 (11:59 +0000)
23 files changed:
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPObjectComparator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionNegotiator.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java
integration-tests/src/test/java/org/opendaylight/protocol/integration/bgp/ParserToSalTest.java
integration-tests/src/test/resources/pcep-hex.txt [new file with mode: 0644]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java
pcep/topology-provider/pom.xml
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java [new file with mode: 0644]
util/pom.xml
util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java [new file with mode: 0644]
util/src/test/java/org/opendaylight/protocol/util/PCEPHexDumpParserTest.java [new file with mode: 0644]
util/src/test/resources/pcep-hex.txt [new file with mode: 0644]

index ddf0b171433c43432c3901a6a4efb418083659e7..e4b626e7a09c9b977ee571c6903c6b81d4f5ee04 100644 (file)
@@ -89,7 +89,6 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                                }
                        }
                }
-
                final byte[] msgBody = new byte[MIN_MSG_LENGTH + optParamsLength];
 
                int offset = 0;
@@ -102,7 +101,6 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                if (openAS > Values.UNSIGNED_SHORT_MAX_VALUE) {
                        openAS = AS_TRANS;
                }
-
                System.arraycopy(ByteArray.longToBytes(openAS, AS_SIZE), 0, msgBody, offset, AS_SIZE);
                offset += AS_SIZE;
 
@@ -121,7 +119,6 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                                index += entry.getValue();
                        }
                }
-
                final byte[] ret = MessageUtil.formatMessage(TYPE, msgBody);
                logger.trace("Open message serialized to: {}", Arrays.toString(ret));
                return ret;
@@ -147,7 +144,6 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                if (UnsignedBytes.toInt(body[0]) != BGP_VERSION) {
                        throw new BGPDocumentedException("BGP Protocol version " + UnsignedBytes.toInt(body[0]) + " not supported.", BGPError.VERSION_NOT_SUPPORTED);
                }
-
                int offset = VERSION_SIZE;
                final AsNumber as = new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(body, offset, AS_SIZE)));
                offset += AS_SIZE;
@@ -159,7 +155,6 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                if (holdTime == 1 || holdTime == 2) {
                        throw new BGPDocumentedException("Hold time value not acceptable.", BGPError.HOLD_TIME_NOT_ACC);
                }
-
                Ipv4Address bgpId = null;
                try {
                        bgpId = Ipv4Util.addressForBytes(ByteArray.subByte(body, offset, BGP_ID_SIZE));
@@ -183,15 +178,12 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Byte array cannot be null or empty.");
                }
-
                logger.trace("Started parsing of BGP parameter: {}", Arrays.toString(bytes));
                int byteOffset = 0;
                while (byteOffset < bytes.length) {
                        if (byteOffset + 2 >= bytes.length) {
-                               // FIXME: throw a BGPDocumentedException here?
-                               throw new IllegalArgumentException("Malformed parameter encountered (" + (bytes.length - byteOffset) + " bytes left)");
+                               throw new BGPDocumentedException("Malformed parameter encountered (" + (bytes.length - byteOffset) + " bytes left)", BGPError.OPT_PARAM_NOT_SUPPORTED);
                        }
-
                        final int paramType = UnsignedBytes.toInt(bytes[byteOffset++]);
                        final int paramLength = UnsignedBytes.toInt(bytes[byteOffset++]);
                        final byte[] paramBody = ByteArray.subByte(bytes, byteOffset, paramLength);
@@ -203,14 +195,12 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                        } catch (final BGPParsingException e) {
                                throw new BGPDocumentedException("Optional parameter not parsed", BGPError.UNSPECIFIC_OPEN_ERROR, e);
                        }
-
                        if (param != null) {
                                params.add(param);
                        } else {
                                logger.debug("Ignoring BGP Parameter type: {}", paramType);
                        }
                }
-
                logger.trace("Parsed BGP parameters: {}", Arrays.toString(params.toArray()));
        }
 }
index 5a73c6b34737ce97f53cb28e443099b184475f1f..fce26f9b62872484ef2eab2a0b1e351e0e3be279 100644 (file)
@@ -15,8 +15,9 @@ import org.opendaylight.protocol.bgp.parser.BGPError;
 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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunitiesBuilder;
 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.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CAsSpecificExtendedCommunityBuilder;
 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.COpaqueExtendedCommunityBuilder;
@@ -36,9 +37,9 @@ import com.google.common.primitives.UnsignedBytes;
  */
 public final class CommunitiesParser {
 
-       public static final int EXTENDED_COMMUNITY_LENGTH = 8;
+       protected static final int EXTENDED_COMMUNITY_LENGTH = 8;
 
-       public static final int COMMUNITY_LENGTH = 4;
+       protected static final int COMMUNITY_LENGTH = 4;
 
        private static final int TYPE_LENGTH = 2;
 
@@ -46,6 +47,24 @@ public final class CommunitiesParser {
 
        private static final int AS_LOCAL_ADMIN_LENGTH = 4;
 
+       protected static final short AS_TYPE_TRANS = 0;
+
+       protected static final short AS_TYPE_NON_TRANS = 40;
+
+       protected static final short INET_TYPE_TRANS = 1;
+
+       protected static final short INET_TYPE_NON_TRANS = 41;
+
+       protected static final short OPAQUE_TYPE_TRANS = 3;
+
+       protected static final short OPAQUE_TYPE_NON_TRANS = 43;
+
+       protected static final short ROUTE_TYPE_ONLY = 2;
+
+       protected static final short ROUTE_TARGET_SUBTYPE = 2;
+
+       protected static final short ROUTE_ORIGIN_SUBTYPE = 3;
+
        private CommunitiesParser() {
 
        }
@@ -80,78 +99,99 @@ public final class 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 {
+       public static ExtendedCommunities parseExtendedCommunity(final byte[] bytes) throws BGPDocumentedException {
                final int type = UnsignedBytes.toInt(bytes[0]);
                final int subType = UnsignedBytes.toInt(bytes[1]);
                final byte[] value = ByteArray.subByte(bytes, TYPE_LENGTH, bytes.length - TYPE_LENGTH);
 
+               ExtendedCommunities comm;
                switch (type) {
-               case 0:
-                       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();
-                       } 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();
+               case AS_TYPE_TRANS:
+                       if (subType == ROUTE_TARGET_SUBTYPE) {
+                               comm = new ExtendedCommunitiesBuilder().setCommType(AS_TYPE_TRANS).setCommSubType(ROUTE_TARGET_SUBTYPE).setExtendedCommunity(
+                                               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()).build();
+                       } else if (subType == ROUTE_ORIGIN_SUBTYPE) {
+                               comm = new ExtendedCommunitiesBuilder().setCommType(AS_TYPE_TRANS).setCommSubType(ROUTE_ORIGIN_SUBTYPE).setExtendedCommunity(
+                                               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()).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();
+                               comm = new ExtendedCommunitiesBuilder().setCommType(AS_TYPE_TRANS).setExtendedCommunity(
+                                               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()).build();
                        }
-               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();
-               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();
-                       } 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();
+                       break;
+               case AS_TYPE_NON_TRANS:
+                       comm = new ExtendedCommunitiesBuilder().setCommType(AS_TYPE_NON_TRANS).setExtendedCommunity(
+                                       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()).build();
+                       break;
+               case ROUTE_TYPE_ONLY:
+                       if (subType == ROUTE_TARGET_SUBTYPE) {
+                               comm = new ExtendedCommunitiesBuilder().setCommType(ROUTE_TYPE_ONLY).setCommSubType(ROUTE_TARGET_SUBTYPE).setExtendedCommunity(
+                                               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()).build();
+                       } else if (subType == ROUTE_ORIGIN_SUBTYPE) {
+                               comm = new ExtendedCommunitiesBuilder().setCommType(ROUTE_TYPE_ONLY).setCommSubType(ROUTE_ORIGIN_SUBTYPE).setExtendedCommunity(
+                                               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()).build();
                        } else {
                                throw new BGPDocumentedException("Could not parse Extended Community subtype: " + subType, BGPError.OPT_ATTR_ERROR);
                        }
-               case 1:
-                       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();
-                       } 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();
+                       break;
+               case INET_TYPE_TRANS:
+                       if (subType == ROUTE_TARGET_SUBTYPE) {
+                               comm = new ExtendedCommunitiesBuilder().setCommType(INET_TYPE_TRANS).setCommSubType(ROUTE_TARGET_SUBTYPE).setExtendedCommunity(
+                                               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()).build();
+                       } else if (subType == ROUTE_ORIGIN_SUBTYPE) {
+                               comm = new ExtendedCommunitiesBuilder().setCommType(INET_TYPE_TRANS).setCommSubType(ROUTE_ORIGIN_SUBTYPE).setExtendedCommunity(
+                                               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()).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();
+                               comm = new ExtendedCommunitiesBuilder().setCommType(INET_TYPE_TRANS).setExtendedCommunity(
+                                               new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
+                                                               new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
+                                                                               Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(
+                                                                               ByteArray.subByte(value, 4, 2)).build()).build()).build();
                        }
-               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:
-                       return new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
-                                       new OpaqueExtendedCommunityBuilder().setTransitive(true).setValue(value).build()).build();
+                       break;
+               case INET_TYPE_NON_TRANS:
+                       comm = new ExtendedCommunitiesBuilder().setCommType(INET_TYPE_NON_TRANS).setExtendedCommunity(
+                                       new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
+                                                       new Inet4SpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
+                                                                       Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(
+                                                                       ByteArray.subByte(value, 4, 2)).build()).build()).build();
+                       break;
+               case OPAQUE_TYPE_TRANS:
+                       comm = new ExtendedCommunitiesBuilder().setCommType(OPAQUE_TYPE_TRANS).setExtendedCommunity(
+                                       new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
+                                                       new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(value).build()).build()).build();
+                       break;
+               case OPAQUE_TYPE_NON_TRANS:
+                       comm = new ExtendedCommunitiesBuilder().setCommType(OPAQUE_TYPE_NON_TRANS).setExtendedCommunity(
+                                       new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
+                                                       new OpaqueExtendedCommunityBuilder().setTransitive(true).setValue(value).build()).build()).build();
+                       break;
                default:
                        throw new BGPDocumentedException("Could not parse Extended Community type: " + type, BGPError.OPT_ATTR_ERROR);
                }
+               return comm;
        }
 }
index e64a57b94106626e57fc0723a99a1675ea72121b..a997f6fc890dacabc27492136609a9a7d3b33fad 100644 (file)
@@ -13,9 +13,7 @@ import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 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.rev130919.path.attributes.ExtendedCommunities;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunitiesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.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;
 
@@ -27,10 +25,10 @@ public final class ExtendedCommunitiesAttributeParser implements AttributeParser
                final List<ExtendedCommunities> set = Lists.newArrayList();
                int i = 0;
                while (i < bytes.length) {
-                       ExtendedCommunity comm = CommunitiesParser.parseExtendedCommunity(ByteArray.subByte(bytes, i,
+                       final ExtendedCommunities comm = CommunitiesParser.parseExtendedCommunity(ByteArray.subByte(bytes, i,
                                        CommunitiesParser.EXTENDED_COMMUNITY_LENGTH));
                        i += CommunitiesParser.EXTENDED_COMMUNITY_LENGTH;
-                       set.add(new ExtendedCommunitiesBuilder().setExtendedCommunity(comm).build());
+                       set.add(comm);
                }
 
                builder.setExtendedCommunities(set);
index 20e6e8996adc55f68bc8fe698cdc21582c3c0c04..7eef7f0dce4d5e0d797f1df501da590b229cf2c3 100644 (file)
@@ -543,7 +543,7 @@ public class BGPParserTest {
                                new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
 
                final List<ExtendedCommunities> comms = Lists.newArrayList();
-               comms.add(new ExtendedCommunitiesBuilder().setExtendedCommunity(
+               comms.add(new ExtendedCommunitiesBuilder().setCommType((short) 1).setExtendedCommunity(
                                new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
                                                new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
                                                                new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
index 7afcc9de0b669de34d9e2a0dd777198f05d45590..6cdca4398f918cd7fefa55d191f0ae918de97d2d 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AggregatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.c.multiprotocol.MultiprotocolCapability;
@@ -75,6 +76,7 @@ public class ComplementaryTest {
                tt.put(t, true);
                tt.put(t1, false);
 
+               // FIXME: revive test for graceful capability tlv
                // final BGPParameter tlv3 = new GracefulCapability(false, 0, tt);
 
                final CParameters tlv4 = new CAs4BytesBuilder().setAs4BytesCapability(
@@ -119,94 +121,111 @@ public class ComplementaryTest {
 
        @Test
        public void testCommunitiesParser() {
-               CAsSpecificExtendedCommunity as = null;
+               ExtendedCommunities as = null;
                try {
-                       as = (CAsSpecificExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 0, 5, 0, 54, 0, 0, 1, 76 });
+                       as = CommunitiesParser.parseExtendedCommunity(new byte[] { 0, 5, 0, 54, 0, 0, 1, 76 });
                } catch (final BGPDocumentedException e1) {
                        fail("Not expected exception: " + e1);
                }
                CAsSpecificExtendedCommunity expected = new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
                                new AsSpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(new AsNumber(54L)).setLocalAdministrator(
                                                new byte[] { 0, 0, 1, 76 }).build()).build();
-               assertEquals(expected.getAsSpecificExtendedCommunity().isTransitive(), as.getAsSpecificExtendedCommunity().isTransitive());
+               CAsSpecificExtendedCommunity result = (CAsSpecificExtendedCommunity) as.getExtendedCommunity();
+               assertEquals(expected.getAsSpecificExtendedCommunity().isTransitive(), result.getAsSpecificExtendedCommunity().isTransitive());
                assertEquals(expected.getAsSpecificExtendedCommunity().getGlobalAdministrator(),
-                               as.getAsSpecificExtendedCommunity().getGlobalAdministrator());
+                               result.getAsSpecificExtendedCommunity().getGlobalAdministrator());
                assertArrayEquals(expected.getAsSpecificExtendedCommunity().getLocalAdministrator(),
-                               as.getAsSpecificExtendedCommunity().getLocalAdministrator());
+                               result.getAsSpecificExtendedCommunity().getLocalAdministrator());
+               assertEquals(0, as.getCommType().intValue());
 
                try {
-                       as = (CAsSpecificExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 40, 5, 0, 54, 0, 0, 1, 76 });
+                       as = CommunitiesParser.parseExtendedCommunity(new byte[] { 40, 5, 0, 54, 0, 0, 1, 76 });
                } catch (final BGPDocumentedException e1) {
                        fail("Not expected exception: " + e1);
                }
                expected = new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
                                new AsSpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(new AsNumber(54L)).setLocalAdministrator(
                                                new byte[] { 0, 0, 1, 76 }).build()).build();
-               assertEquals(expected.getAsSpecificExtendedCommunity().isTransitive(), as.getAsSpecificExtendedCommunity().isTransitive());
+               result = (CAsSpecificExtendedCommunity) as.getExtendedCommunity();
+               assertEquals(expected.getAsSpecificExtendedCommunity().isTransitive(), result.getAsSpecificExtendedCommunity().isTransitive());
+               assertEquals(40, as.getCommType().intValue());
 
-               CRouteTargetExtendedCommunity rtc = null;
+               ExtendedCommunities rtc = null;
                try {
-                       rtc = (CRouteTargetExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 1, 2, 0, 35, 4, 2, 8, 7 });
+                       rtc = CommunitiesParser.parseExtendedCommunity(new byte[] { 1, 2, 0, 35, 4, 2, 8, 7 });
                } catch (final BGPDocumentedException e1) {
                        fail("Not expected exception: " + e1);
                }
                final CRouteTargetExtendedCommunity rexpected = new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
                                new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(new AsNumber(35L)).setLocalAdministrator(
                                                new byte[] { 4, 2, 8, 7 }).build()).build();
+               final CRouteTargetExtendedCommunity rresult = (CRouteTargetExtendedCommunity) rtc.getExtendedCommunity();
                assertEquals(rexpected.getRouteTargetExtendedCommunity().getGlobalAdministrator(),
-                               rtc.getRouteTargetExtendedCommunity().getGlobalAdministrator());
+                               rresult.getRouteTargetExtendedCommunity().getGlobalAdministrator());
                assertArrayEquals(rexpected.getRouteTargetExtendedCommunity().getLocalAdministrator(),
-                               rtc.getRouteTargetExtendedCommunity().getLocalAdministrator());
+                               rresult.getRouteTargetExtendedCommunity().getLocalAdministrator());
+               assertEquals(1, rtc.getCommType().intValue());
+               assertEquals(2, rtc.getCommSubType().intValue());
 
-               CRouteOriginExtendedCommunity roc = null;
+               ExtendedCommunities roc = null;
                try {
-                       roc = (CRouteOriginExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 0, 3, 0, 24, 4, 2, 8, 7 });
+                       roc = CommunitiesParser.parseExtendedCommunity(new byte[] { 0, 3, 0, 24, 4, 2, 8, 7 });
                } catch (final BGPDocumentedException e1) {
                        fail("Not expected exception: " + e1);
                }
                final CRouteOriginExtendedCommunity oexpected = new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
                                new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(new AsNumber(24L)).setLocalAdministrator(
                                                new byte[] { 4, 2, 8, 7 }).build()).build();
+               final CRouteOriginExtendedCommunity oresult = (CRouteOriginExtendedCommunity) roc.getExtendedCommunity();
                assertEquals(oexpected.getRouteOriginExtendedCommunity().getGlobalAdministrator(),
-                               roc.getRouteOriginExtendedCommunity().getGlobalAdministrator());
+                               oresult.getRouteOriginExtendedCommunity().getGlobalAdministrator());
                assertArrayEquals(oexpected.getRouteOriginExtendedCommunity().getLocalAdministrator(),
-                               roc.getRouteOriginExtendedCommunity().getLocalAdministrator());
+                               oresult.getRouteOriginExtendedCommunity().getLocalAdministrator());
+               assertEquals(0, roc.getCommType().intValue());
+               assertEquals(3, roc.getCommSubType().intValue());
 
-               CInet4SpecificExtendedCommunity sec = null;
+               ExtendedCommunities sec = null;
                try {
-                       sec = (CInet4SpecificExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 41, 6, 12, 51, 2, 5, 21, 45 });
+                       sec = CommunitiesParser.parseExtendedCommunity(new byte[] { 41, 6, 12, 51, 2, 5, 21, 45 });
                } catch (final BGPDocumentedException e1) {
                        fail("Not expected exception: " + e1);
                }
                final CInet4SpecificExtendedCommunity iexpected = new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
                                new Inet4SpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(new Ipv4Address("12.51.2.5")).setLocalAdministrator(
                                                new byte[] { 21, 45 }).build()).build();
-               assertEquals(iexpected.getInet4SpecificExtendedCommunity().isTransitive(), sec.getInet4SpecificExtendedCommunity().isTransitive());
+               final CInet4SpecificExtendedCommunity iresult = (CInet4SpecificExtendedCommunity) sec.getExtendedCommunity();
+               assertEquals(iexpected.getInet4SpecificExtendedCommunity().isTransitive(),
+                               iresult.getInet4SpecificExtendedCommunity().isTransitive());
                assertEquals(iexpected.getInet4SpecificExtendedCommunity().getGlobalAdministrator(),
-                               sec.getInet4SpecificExtendedCommunity().getGlobalAdministrator());
+                               iresult.getInet4SpecificExtendedCommunity().getGlobalAdministrator());
                assertArrayEquals(iexpected.getInet4SpecificExtendedCommunity().getLocalAdministrator(),
-                               sec.getInet4SpecificExtendedCommunity().getLocalAdministrator());
+                               iresult.getInet4SpecificExtendedCommunity().getLocalAdministrator());
+               assertEquals(41, sec.getCommType().intValue());
 
-               COpaqueExtendedCommunity oec = null;
+               ExtendedCommunities oec = null;
                try {
-                       oec = (COpaqueExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 3, 6, 21, 45, 5, 4, 3, 1 });
+                       oec = CommunitiesParser.parseExtendedCommunity(new byte[] { 3, 6, 21, 45, 5, 4, 3, 1 });
                } catch (final BGPDocumentedException e1) {
                        fail("Not expected exception: " + e1);
                }
                final COpaqueExtendedCommunity oeexpected = new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
                                new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(new byte[] { 21, 45, 5, 4, 3, 1 }).build()).build();
-               assertEquals(oeexpected.getOpaqueExtendedCommunity().isTransitive(), oec.getOpaqueExtendedCommunity().isTransitive());
-               assertArrayEquals(oeexpected.getOpaqueExtendedCommunity().getValue(), oec.getOpaqueExtendedCommunity().getValue());
+               final COpaqueExtendedCommunity oeresult = (COpaqueExtendedCommunity) oec.getExtendedCommunity();
+               assertEquals(oeexpected.getOpaqueExtendedCommunity().isTransitive(), oeresult.getOpaqueExtendedCommunity().isTransitive());
+               assertArrayEquals(oeexpected.getOpaqueExtendedCommunity().getValue(), oeresult.getOpaqueExtendedCommunity().getValue());
+               assertEquals(3, oec.getCommType().intValue());
 
                try {
-                       oec = (COpaqueExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 43, 6, 21, 45, 5, 4, 3, 1 });
+                       oec = CommunitiesParser.parseExtendedCommunity(new byte[] { 43, 6, 21, 45, 5, 4, 3, 1 });
                } catch (final BGPDocumentedException e1) {
                        fail("Not expected exception: " + e1);
                }
                final COpaqueExtendedCommunity oeexpected1 = new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
                                new OpaqueExtendedCommunityBuilder().setTransitive(true).setValue(new byte[] { 21, 45, 5, 4, 3, 1 }).build()).build();
-               assertEquals(oeexpected1.getOpaqueExtendedCommunity().isTransitive(), oec.getOpaqueExtendedCommunity().isTransitive());
-               assertArrayEquals(oeexpected1.getOpaqueExtendedCommunity().getValue(), oec.getOpaqueExtendedCommunity().getValue());
+               final COpaqueExtendedCommunity oeresult1 = (COpaqueExtendedCommunity) oec.getExtendedCommunity();
+               assertEquals(oeexpected1.getOpaqueExtendedCommunity().isTransitive(), oeresult1.getOpaqueExtendedCommunity().isTransitive());
+               assertArrayEquals(oeexpected1.getOpaqueExtendedCommunity().getValue(), oeresult1.getOpaqueExtendedCommunity().getValue());
+               assertEquals(43, oec.getCommType().intValue());
 
                try {
                        CommunitiesParser.parseExtendedCommunity(new byte[] { 11, 11, 21, 45, 5, 4, 3, 1 });
index 778e547ae5708f9e9f21b486a6cc7478e3c189a4..d252af29e4d6338bf091be290a1d7f3babc5e540 100644 (file)
@@ -36,8 +36,7 @@ final class BGPObjectComparator implements Comparator<PathAttributes> {
                        return 0;
                }
 
-               // FIXME: look at ASPath
-               // FIXME: look at everything else :-)
+               // FIXME: BUG-185: implement here
 
                return 0;
        }
index bdc47689fd6c8c0e5ae08420b64a59b978121e20..846bb909c5343e0e2a089eb76eceb762a9a7627d 100644 (file)
@@ -43,8 +43,7 @@ import com.google.common.base.Preconditions;
 
 public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notification, BGPSessionImpl> {
        // 4 minutes recommended in http://tools.ietf.org/html/rfc4271#section-8.2.2
-       // FIXME to actual value
-       protected static final int INITIAL_HOLDTIMER = 1;
+       protected static final int INITIAL_HOLDTIMER = 4;
 
        @VisibleForTesting
        public enum State {
index 9ea256ba6b79ccb8c7e78e24369826356e68e805..82a6515975e1e0d19560595fa60e934f72b9e03a 100644 (file)
@@ -36,7 +36,7 @@ import com.google.common.io.CharStreams;
 @Immutable
 public final class HexDumpBGPFileParser {
        private static final int MINIMAL_LENGTH = 19;
-       private static final Logger logger = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
+       private static final Logger LOG = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
        private static final String FF_16 = Strings.repeat("FF", 16);
 
        private HexDumpBGPFileParser() {
@@ -62,8 +62,8 @@ public final class HexDumpBGPFileParser {
                // search for 16 FFs
 
                final List<byte[]> messages = Lists.newLinkedList();
-               int idx = 0;
-               while ((idx = content.indexOf(FF_16, idx)) > -1) {
+               int idx = content.indexOf(FF_16, 0);
+               while (idx > -1) {
                        // next 2 bytes are length
                        final int lengthIdx = idx + 16 * 2;
                        final int messageIdx = lengthIdx + 4;
@@ -91,8 +91,9 @@ public final class HexDumpBGPFileParser {
                        }
                        messages.add(message);
                        idx = messageEndIdx;
+                       idx = content.indexOf(FF_16, idx);
                }
-               logger.info("Succesfully extracted {} messages", messages.size());
+               LOG.info("Succesfully extracted {} messages", messages.size());
                return messages;
        }
 
@@ -100,5 +101,4 @@ public final class HexDumpBGPFileParser {
        static String clearWhiteSpaceToUpper(final String line) {
                return line.replaceAll("\\s", "").toUpperCase();
        }
-
 }
index 943093a2c832ac1f73f80977da9e40ead129e4a3..4ef07d9c9ba4f716253043f66e82cdd532bacbfe 100644 (file)
@@ -82,7 +82,6 @@ public class ParserToSalTest {
 
                        @Override
                        public boolean isCancelled() {
-                               // TODO Auto-generated method stub
                                return false;
                        }
 
@@ -95,14 +94,12 @@ public class ParserToSalTest {
 
                        @Override
                        public RpcResult<TransactionStatus> get() throws InterruptedException, ExecutionException {
-                               // TODO Auto-generated method stub
                                return null;
                        }
 
                        @Override
                        public RpcResult<TransactionStatus> get(final long timeout, final TimeUnit unit) throws InterruptedException,
-                       ExecutionException, TimeoutException {
-                               // TODO Auto-generated method stub
+                                       ExecutionException, TimeoutException {
                                return null;
                        }
                }).when(this.mockedTransaction).commit();
diff --git a/integration-tests/src/test/resources/pcep-hex.txt b/integration-tests/src/test/resources/pcep-hex.txt
new file mode 100644 (file)
index 0000000..434a46c
--- /dev/null
@@ -0,0 +1,37 @@
+Received PCEP Open message. Length:28.
+
+20 01 00 1c 01 10 00 18  20 1e 78 03 00 10 00 04
+00 00 00 05 00 1a 00 04  00 00 00 b4
+
+Received PCEP Keepalive message. Length:4.
+
+20 02 00 04
+
+Received PCEPReport message. Length:12.
+
+20 0a 00 0c 20 10 00 08  00 00 00 00
+
+Received PCEPReport message. Length:56.
+
+20 0a 00 38 20 10 00 34  00 00 50 01 00 11 00 28
+74 75 6e 6e 65 6c 5f 66  72 6f 6d 5f 4f 66 2d 39
+6b 2d 30 32 5f 74 6f 5f  4f 66 2d 39 6b 2d 30 33
+4f 66 2d 39 6b 2d 30 32
+
+Received PCEPReport message. Length:120.
+
+20 0a 00 78 20 10 00 44  00 00 50 05 00 11 00 28
+74 75 6e 6e 65 6c 5f 66  72 6f 6d 5f 4f 66 2d 39
+6b 2d 30 32 5f 74 6f 5f  4f 66 2d 39 6b 2d 30 33
+4f 66 2d 39 6b 2d 30 32  00 12 00 0c 2a 2a 2a 2a
+00 00 00 04 2a 2a 2a 2a  07 10 00 14 01 08 c6 14
+a0 2b 20 00 01 08 2b 2b  2b 2b 20 00 09 10 00 14
+00 00 00 00 00 00 00 00  00 00 00 00 07 07 00 00
+05 20 00 08 00 00 00 00
+
+Received PCEPReport message. Length:56.
+
+20 0a 00 38 20 10 00 34  00 00 50 0c 00 11 00 28
+74 75 6e 6e 65 6c 5f 66  72 6f 6d 5f 4f 66 2d 39
+6b 2d 30 32 5f 74 6f 5f  4f 66 2d 39 6b 2d 30 33
+4f 66 2d 39 6b 2d 30 32
index b64e3be9be7981c67f7622e476dc33e3f4fae143..10527cee74ed595e536211e8a10bc77da8eb0420 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 
 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
@@ -38,7 +39,8 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot
        }
 
        @Override
-       protected PCEPSessionImpl createSession(final Timer timer, final Channel channel, final Open localPrefs, final Open remotePrefs) {
+       @VisibleForTesting
+       public PCEPSessionImpl createSession(final Timer timer, final Channel channel, final Open localPrefs, final Open remotePrefs) {
                return new PCEPSessionImpl(timer, this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
        }
 
index 5804abe17af09f5edafde2f600d8c508ba6dec95..4302612e30876524bad0a1081c08f98be7972ae2 100644 (file)
@@ -384,7 +384,8 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
        }
 
        @Override
-       protected void sessionUp() {
+       @VisibleForTesting
+       public void sessionUp() {
                this.listener.onSessionUp(this);
        }
 
index c6e3ecb8cdb59f4e40a6a2a007059a37d2f2e76e..0b44ffd2927aeacb40a20493135e43deb5ec2d1e 100644 (file)
@@ -46,8 +46,9 @@ public class PCEPKeepAliveMessageParser extends AbstractMessageParser {
 
        @Override
        protected KeepaliveMessage validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
-               // FIXME: keepalive shouldn't have objects
-
+               if (objects != null && !objects.isEmpty()) {
+                       throw new PCEPDeserializerException("Keepalive message should not contain any objects.");
+               }
                return MESSAGE;
        }
 }
index df73f772a45c4b2ac4e97aa1aa6d025ec6e24502..fe625f586397775775c79407228ad7d685faa4bf 100644 (file)
@@ -114,7 +114,7 @@ public final class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
                byteOffset += USER_VALUE_F_LENGTH;
                error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
                byteOffset += errDescrLength;
-               // TODO: if we have any subobjects
+               // if we have any subobjects, place the implementation here
                return new UserBuilder().setUserError(error.build()).build();
        }
 
@@ -124,7 +124,7 @@ public final class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
                final byte[] value = ByteArray.intToBytes(ue.getValue(), 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
+               // if we have any subobjects, place the implementation here
                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);
index 4a091e5f57a54b21c5479221dbacc07b8306eec4..6d002cc9db954cc415479760f1fb16850a285f31 100644 (file)
@@ -242,7 +242,7 @@ public class PCEPObjectParserTest {
                builder.setSubobjects(subs);
 
                assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
-               // FIXME: fix Ipv6Serializers (getType)
+               // FIXME: BUG-130: fix Ipv6Serializers (getType)
                // assertArrayEquals(result, parser.serializeObject(builder.build()));
        }
 
@@ -263,14 +263,14 @@ public class PCEPObjectParserTest {
                subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectsBuilder().setSubobjectType(
                                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixBuilder().setIpPrefix(
                                                new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).setProtectionAvailable(false).setProtectionInUse(
-                                                               false).build());
+                               false).build());
                subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectsBuilder().setSubobjectType(
                                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedBuilder().setRouterId(
                                                0x1245678L).setInterfaceId(0x9abcdef0L).build()).setProtectionAvailable(false).setProtectionInUse(false).build());
                builder.setSubobjects(subs);
 
                assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
-               // FIXME: fix Ipv6Serializers (getType)
+               // FIXME: BUG-130: fix Ipv6Serializers (getType)
                // assertArrayEquals(result, parser.serializeObject(builder.build()));
        }
 
index 807a31323159fa7b9a26765a77c6921fe11f5bcf..75168ba1acf31e71283da1704238dda8802c1e97 100644 (file)
@@ -390,176 +390,6 @@ public class PCEPValidatorTest {
                buf = Unpooled.buffer(result.length);
                parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
                assertArrayEquals(result, buf.array());
-
-               // specMessages.clear();
-               // requests = new ArrayList<CompositeRequestObject>();
-               // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
-               // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null));
-               // specMessages.add(new PCEPRequestMessage(requests));
-               //
-               // final byte[] ipAdress3 = { (byte) 0x7F, (byte) 0x00, (byte) 0x30, (byte) 0x01 };
-               // requests = new ArrayList<CompositeRequestObject>();
-               // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(false, false, false, false, false,
-               // false,
-               // false, false, (short) 4, 1, true, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(ipAdress3),
-               // new
-               // IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null));
-               // specMessages.add(new PCEPRequestMessage(requests));
-               //
-               // final byte[] ipAdress4 = { (byte) 0x7F, (byte) 0x30, (byte) 0x00, (byte) 0x01 };
-               // requests = new ArrayList<CompositeRequestObject>();
-               // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
-               // IPv4Address(ipAdress2), new IPv4Address(ipAdress4)), null, null, null, null, null, null, null, null, null));
-               // specMessages.add(new PCEPRequestMessage(requests));
-               //
-               // final byte[] ipAdress5 = { (byte) 0x7F, (byte) 0xd0, (byte) 0x00, (byte) 0x01 };
-               // requests = new ArrayList<CompositeRequestObject>();
-               // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false,
-               // false,
-               // false, false, (short) 1, 1, true, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(ipAdress5),
-               // new
-               // IPv4Address(ipAdress5)), null, null, null, null, null, null, null, null, null));
-               //
-               // specMessages.add(new PCEPRequestMessage(requests));
-               // deserMsgs = deserMsg("src/test/resources/PCReq.4.bin");
-               // assertEquals(deserMsgs.toString(), specMessages.toString());
-               //
-               // specMessages.clear();
-               // svecList = new ArrayList<CompositeRequestSvecObject>();
-               // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false,
-               // this.requestIds,
-               // false)));
-               // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(false, true, true, false, false,
-               // this.requestIds,
-               // false), new PCEPObjectiveFunctionObject(PCEPOFCodes.MCC, true, false), new
-               // PCEPGlobalConstraintsObject((short)
-               // 0x55, (short) 1, (short) 100, (short) 0x26, true, false), new PCEPExcludeRouteObject(new
-               // ArrayList<ExcludeRouteSubobject>() {
-               // private static final long serialVersionUID = 1L;
-               //
-               // {
-               // this.add(new XROAsNumberSubobject(new AsNumber((long) 0x12), true));
-               // }
-               // }, true, true, false), new ArrayList<PCEPMetricObject>() {
-               // private static final long serialVersionUID = 1L;
-               //
-               // {
-               // this.add(new PCEPMetricObject(true, true, new TEMetric(123456L), true, false));
-               // }
-               // }));
-               //
-               // requests = new ArrayList<CompositeRequestObject>();
-               // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
-               // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, PCEPValidatorTest.lspa, new
-               // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new
-               // ArrayList<PCEPMetricObject>() {
-               // private static final long serialVersionUID = 1L;
-               //
-               // {
-               // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false));
-               // this.add(new PCEPMetricObject(true, true, new IGPMetric(5335L), false, false));
-               // this.add(new PCEPMetricObject(true, true, new IGPMetric(128256), false, false));
-               // }
-               // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new
-               // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false,
-               // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false)));
-               //
-               // final byte[] ipAdress6 = { (byte) 0x7F, (byte) 0xF0, (byte) 0x00, (byte) 0x01 };
-               // specMessages.add(new PCEPRequestMessage(svecList, requests));
-               //
-               // requests = new ArrayList<CompositeRequestObject>();
-               // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject<IPv4Address>(new
-               // IPv4Address(ipAdress6), new IPv4Address(ipAdress6)), null, null, PCEPValidatorTest.lspa, new
-               // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new
-               // ArrayList<PCEPMetricObject>() {
-               // private static final long serialVersionUID = 1L;
-               //
-               // {
-               // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false));
-               // }
-               // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new
-               // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false,
-               // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3f)), false)));
-               // deserMsgs = deserMsg("src/test/resources/PCReq.5.bin");
-               // specMessages.add(new PCEPRequestMessage(svecList, requests));
-               // // FIXME
-               // // assertEquals(deserMsgs, specMessages);
-               //
-               // // FIXME: need construct with invalid processed parameter
-               // // assertEquals(deserMsg("src/test/resources/PCReq.6.invalid.bin"),
-               // // asList(
-               // // new PCEPErrorMessage(new CompositeErrorObject(new
-               // // PCEPRequestParameterObject(true, false, false, false, false, false,
-               // // false, false, (short) 3,
-               // // 1L, false, false), new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))),
-               // // new PCEPRequestMessage(asList(new
-               // // CompositeRequestObject(this.requestParameter, new
-               // // PCEPEndPointsObject<IPv4Address>(IPv4Address
-               // // .getNetworkAddressFactory().getNetworkAddressForBytes(new byte[] {
-               // // 127, 0, 0, 1 }), IPv4Address.getNetworkAddressFactory()
-               // // .getNetworkAddressForBytes(new byte[] { 127, 0, 0, 1 })), null, null,
-               // // null, null, null, null, null, null, new PCEPLoadBalancingObject(
-               // // 3, new Bandwidth(1024.75), false))))));
-               //
-               // }
-               //
-               // @Test
-               // public void testRequestMessageValidationFromRawMsg() throws PCEPDeserializerException {
-               // List<PCEPObject> objs = new ArrayList<PCEPObject>();
-               // List<Message> msgs;
-               // PCEPRequestParameterObject tmpRP;
-               //
-               // // test unrecognized object in svec list
-               // objs.add(this.svecObj);
-               // objs.add(new UnknownObject(true, false, PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
-               // objs.add(new PCEPSvecObject(true, true, true, false, false, PCEPValidatorTest.this.requestIds, true));
-               //
-               // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs);
-               //
-               // assertEquals(msgs.get(0).toString(), new PCEPErrorMessage(new ArrayList<PCEPErrorObject>() {
-               // private static final long serialVersionUID = 1L;
-               //
-               // {
-               // this.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
-               // }
-               // }).toString());
-               //
-               // // test with request p flag not set and ignoracion of more than one
-               // // end-points objects
-               // objs = new ArrayList<PCEPObject>();
-               // objs.add(this.svecObj);
-               // objs.add(this.svecObj);
-               // tmpRP = new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1,
-               // false, false);
-               // objs.add(tmpRP);
-               // objs.add(this.endPoints);
-               //
-               // objs.add(this.requestParameter);
-               // objs.add(this.endPoints);
-               // objs.add(this.endPoints);
-               // // FIXME:mv use object constructor with set processed flag
-               // // objs.add(this.classTypeProvider);
-               // // objs.add(this.requestParameter);
-               // // objs.add(this.endPointsProvider);
-               // // objs.add(new PCEPClassTypeObjectProvider((short) 7, false));
-               //
-               // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs);
-               // // FIXME:mv use object constructor with set processed flag
-               // // assertEquals(msgs.get(0), new PCEPErrorMessage(new
-               // // CompositeErrorObject(tmpRP, new
-               // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
-               // // assertEquals(
-               // // msgs.get(1),
-               // // new PCEPRequestMessage(asList(new
-               // // CompositeRequestSvecObject(this.svecObj), new
-               // // CompositeRequestSvecObject(this.svecObj)), Util
-               // // .asList(new CompositeRequestObject(this.requestParameter,
-               // // this.endPoints, this.classType, null, null, null, null, null, null,
-               // // null,
-               // // null))));
-               // // assertEquals(msgs.get(2), new PCEPErrorMessage(new
-               // // CompositeErrorObject(tmpRP, new
-               // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))));
        }
 
        @Test
index ed88e892f5ed229d53076ad0e71d3bda09a99b13..53cdd3cec514cc8ea03298a4d3bd7a7b0ded6544 100644 (file)
                        <groupId>${project.groupId}</groupId>
                        <artifactId>mockito-configuration</artifactId>
         </dependency>
+        <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>pcep-impl</artifactId>
+                       <scope>test</scope>
+               </dependency>
+        <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+               </dependency>
        </dependencies>
 
        <build>
index 8a74cde694f8c11a8c3e33782e3c51b78948479d..cba6cdb58ebda0e1ab0bb48446a851d12d285da4 100644 (file)
@@ -10,9 +10,11 @@ package org.opendaylight.bgpcep.pcep.topology.provider;
 import io.netty.util.concurrent.FutureListener;
 
 import java.net.InetAddress;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.ExecutionException;
 
 import javax.annotation.concurrent.GuardedBy;
 
@@ -60,17 +62,23 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TopologyTypes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TopologyTypes1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClientBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.StatefulTlvBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.topology.pcep.type.TopologyPcepBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 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.TopologyBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -88,7 +96,7 @@ import com.google.common.util.concurrent.SettableFuture;
 /**
  *
  */
-final class ServerSessionManager implements SessionListenerFactory<PCEPSessionListener> {
+final class ServerSessionManager implements SessionListenerFactory<PCEPSessionListener>, AutoCloseable {
        private static String createNodeId(final InetAddress addr) {
                return "pcc://" + addr.getHostAddress();
        }
@@ -191,13 +199,12 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                        final DataModificationTransaction trans = ServerSessionManager.this.dataProvider.beginTransaction();
 
                        // The session went down. Undo all the Topology changes we have done.
-                       trans.removeRuntimeData(this.topologyAugment);
+                       trans.removeOperationalData(this.topologyAugment);
                        if (this.ownsTopology) {
-                               trans.removeRuntimeData(this.topologyNode);
+                               trans.removeOperationalData(this.topologyNode);
                        }
 
-                       Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.commit()),
-                                       new FutureCallback<RpcResult<TransactionStatus>>() {
+                       Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.commit()), new FutureCallback<RpcResult<TransactionStatus>>() {
                                @Override
                                public void onSuccess(final RpcResult<TransactionStatus> result) {
                                        // Nothing to do
@@ -237,9 +244,8 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                }
 
                private InstanceIdentifier<ReportedLsps> lspIdentifier(final SymbolicPathName name) {
-                       return InstanceIdentifier.builder(this.topologyAugment).
-                                       child(PathComputationClient.class).
-                                       child(ReportedLsps.class, new ReportedLspsKey(name.getPathName())).toInstance();
+                       return InstanceIdentifier.builder(this.topologyAugment).child(PathComputationClient.class).child(ReportedLsps.class,
+                                       new ReportedLspsKey(name.getPathName())).toInstance();
                }
 
                @Override
@@ -292,7 +298,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                                if (lsp.isRemove()) {
                                        final SymbolicPathName name = this.lsps.remove(id);
                                        if (name != null) {
-                                               trans.removeRuntimeData(lspIdentifier(name));
+                                               trans.removeOperationalData(lspIdentifier(name));
                                        }
 
                                        LOG.debug("LSP {} removed", lsp);
@@ -307,6 +313,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                                                        // TODO: what should we do here?
                                                        continue;
                                                }
+                                               this.lsps.put(id, name);
                                        }
 
                                        final SymbolicPathName name = this.lsps.get(id);
@@ -316,8 +323,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                                }
                        }
 
-                       Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.commit()),
-                                       new FutureCallback<RpcResult<TransactionStatus>>() {
+                       Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.commit()), new FutureCallback<RpcResult<TransactionStatus>>() {
                                @Override
                                public void onSuccess(final RpcResult<TransactionStatus> result) {
                                        // Nothing to do
@@ -391,6 +397,24 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
        public ServerSessionManager(final DataProviderService dataProvider, final InstanceIdentifier<Topology> topology) {
                this.dataProvider = Preconditions.checkNotNull(dataProvider);
                this.topology = Preconditions.checkNotNull(topology);
+
+               // Make sure the topology does not exist
+               final Object c = dataProvider.readOperationalData(topology);
+               Preconditions.checkArgument(c == null, "Topology %s already exists", topology);
+
+               // Now create the base topology
+               final TopologyKey k = InstanceIdentifier.keyOf(topology);
+               final DataModificationTransaction t = dataProvider.beginTransaction();
+               t.putOperationalData(
+                               topology,
+                               new TopologyBuilder().setKey(k).setTopologyId(k.getTopologyId()).setTopologyTypes(
+                                               new TopologyTypesBuilder().addAugmentation(TopologyTypes1.class,
+                                                               new TopologyTypes1Builder().setTopologyPcep(new TopologyPcepBuilder().build()).build()).build()).setNode(
+                                               new ArrayList<Node>()).build());
+
+               // FIXME: attach to the future to notify of failures
+               t.commit();
+
        }
 
        @Override
@@ -407,9 +431,8 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                }
 
                // Make sure there is no such LSP
-               final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).
-                               child(PathComputationClient.class).
-                               child(ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
+               final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).child(PathComputationClient.class).child(
+                               ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
                if (this.dataProvider.readOperationalData(lsp) != null) {
                        LOG.debug("Node {} already contains lsp {} at {}", input.getNode(), input.getName(), lsp);
                        return Futures.immediateFuture(OPERATION_UNSENT);
@@ -451,9 +474,8 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                }
 
                // Make sure the LSP exists, we need it for PLSP-ID
-               final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).
-                               child(PathComputationClient.class).
-                               child(ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
+               final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).child(PathComputationClient.class).child(
+                               ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
                final ReportedLsps rep = (ReportedLsps) this.dataProvider.readOperationalData(lsp);
                if (rep == null) {
                        LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
@@ -479,9 +501,8 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                }
 
                // Make sure the LSP exists
-               final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).
-                               child(PathComputationClient.class).
-                               child(ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
+               final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).child(PathComputationClient.class).child(
+                               ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
                final ReportedLsps rep = (ReportedLsps) this.dataProvider.readOperationalData(lsp);
                if (rep == null) {
                        LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
@@ -525,4 +546,11 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                        return Futures.immediateFuture(OPERATION_UNSENT);
                }
        }
+
+       @Override
+       public void close() throws InterruptedException, ExecutionException {
+               final DataModificationTransaction t = this.dataProvider.beginTransaction();
+               t.removeOperationalData(this.topology);
+               t.commit().get();
+       }
 }
diff --git a/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java b/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java
new file mode 100644 (file)
index 0000000..ab680f8
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * 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.pcep.topology.provider;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelPipeline;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.concurrent.Promise;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+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.pcep.impl.DefaultPCEPSessionNegotiator;
+import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcrpt;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrptBuilder;
+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.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.LspBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessageBuilder;
+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.ReportsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.symbolic.path.name.tlv.SymbolicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+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.TopologyKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+public class ParserToSalTest {
+
+       private static final Logger LOG = LoggerFactory.getLogger(ParserToSalTest.class);
+
+       private List<Notification> receivedMsgs;
+
+       private PCEPSessionImpl session;
+
+       @Mock
+       private Channel clientListener;
+
+       @Mock
+       private ChannelPipeline pipeline;
+
+       @Mock
+       DataProviderService providerService;
+
+       @Mock
+       DataModificationTransaction mockedTransaction;
+
+       private final Open localPrefs = new OpenBuilder().setDeadTimer((short) 30).setKeepalive((short) 10).setTlvs(
+                       new TlvsBuilder().setStateful(new StatefulBuilder().build()).build()).build();
+
+       private Pcrpt rptmsg;
+
+       @Before
+       public void setUp() throws IOException {
+               MockitoAnnotations.initMocks(this);
+
+               doAnswer(new Answer<Object>() {
+                       @Override
+                       public Object answer(final InvocationOnMock invocation) {
+                               final Object[] args = invocation.getArguments();
+                               ParserToSalTest.this.receivedMsgs.add((Notification) args[0]);
+                               return mock(ChannelFuture.class);
+                       }
+               }).when(this.clientListener).writeAndFlush(any(Notification.class));
+               doReturn("TestingChannel").when(this.clientListener).toString();
+               doReturn(this.pipeline).when(this.clientListener).pipeline();
+               doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
+               doReturn(true).when(this.clientListener).isActive();
+               final SocketAddress sa = new InetSocketAddress("127.0.0.1", 4189);
+               doReturn(sa).when(this.clientListener).remoteAddress();
+               doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
+
+               Mockito.doReturn(this.mockedTransaction).when(this.providerService).beginTransaction();
+               Mockito.doReturn(new Future<RpcResult<TransactionStatus>>() {
+                       int i = 0;
+
+                       @Override
+                       public boolean cancel(final boolean mayInterruptIfRunning) {
+                               LOG.debug("Cancel.");
+                               return false;
+                       }
+
+                       @Override
+                       public boolean isCancelled() {
+                               LOG.debug("Is cancelled.");
+                               return false;
+                       }
+
+                       @Override
+                       public boolean isDone() {
+                               this.i++;
+                               LOG.debug("Done. {}", this.i);
+                               return true;
+                       }
+
+                       @Override
+                       public RpcResult<TransactionStatus> get() throws InterruptedException, ExecutionException {
+                               return null;
+                       }
+
+                       @Override
+                       public RpcResult<TransactionStatus> get(final long timeout, final TimeUnit unit) throws InterruptedException,
+                                       ExecutionException, TimeoutException {
+                               return null;
+                       }
+               }).when(this.mockedTransaction).commit();
+
+               final HashMap<Object, Object> data = new HashMap<>();
+
+               Mockito.doAnswer(new Answer<Object>() {
+                       @Override
+                       public Object answer(final InvocationOnMock invocation) throws Throwable {
+                               final Object[] args = invocation.getArguments();
+                               LOG.debug("Get key {}", args[0]);
+                               return data.get(args[0]);
+                       }
+
+               }).when(this.mockedTransaction).readOperationalData(Matchers.any(InstanceIdentifier.class));
+
+               Mockito.doAnswer(new Answer<Object>() {
+                       @Override
+                       public Object answer(final InvocationOnMock invocation) throws Throwable {
+                               final Object[] args = invocation.getArguments();
+                               LOG.debug("Get key {}", args[0]);
+                               return data.get(args[0]);
+                       }
+
+               }).when(this.providerService).readOperationalData(Matchers.any(InstanceIdentifier.class));
+
+               Mockito.doAnswer(new Answer<String>() {
+                       @Override
+                       public String answer(final InvocationOnMock invocation) throws Throwable {
+                               final Object[] args = invocation.getArguments();
+                               LOG.debug("Put key {} value {}", args[0]);
+                               LOG.debug("Put value {}", args[1]);
+                               data.put(args[0], args[1]);
+                               return null;
+                       }
+
+               }).when(this.mockedTransaction).putOperationalData(Matchers.any(InstanceIdentifier.class), Matchers.any(DataObject.class));
+
+               final ServerSessionManager manager = new ServerSessionManager(this.providerService, InstanceIdentifier.builder(
+                               NetworkTopology.class).child(Topology.class, new TopologyKey(new TopologyId("testtopo"))).toInstance());
+               final DefaultPCEPSessionNegotiator neg = new DefaultPCEPSessionNegotiator(new HashedWheelTimer(), mock(Promise.class), this.clientListener, manager.getSessionListener(), (short) 1, 5, this.localPrefs);
+               this.session = neg.createSession(new HashedWheelTimer(), this.clientListener, this.localPrefs, this.localPrefs);
+
+               final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setLsp(
+                               new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
+                                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.lsp.TlvsBuilder().setSymbolicPathName(
+                                                               new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
+               this.rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
+       }
+
+       @Test
+       public void testUnknownLsp() {
+               this.session.sessionUp();
+               this.session.handleMessage(this.rptmsg);
+               Mockito.verify(this.mockedTransaction, Mockito.times(4)).putOperationalData(Matchers.any(InstanceIdentifier.class),
+                               Matchers.any(DataObject.class));
+               Mockito.verify(this.mockedTransaction, Mockito.times(3)).commit();
+       }
+}
index c93f1693a4850d73e7589cea3a7bd3b070a178b3..32b064519faebe1d190c587e5f9d2edad92b0d10 100644 (file)
                        <artifactId>commons-codec</artifactId>
                        <version>${commonscodec.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
 
         <!-- Testing dependencies -->
         <dependency>
diff --git a/util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java b/util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java
new file mode 100644 (file)
index 0000000..b9ccb90
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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 java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Hex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.io.CharStreams;
+
+/**
+ * Parses PCEP messages from a text file. Messages need to follow this formatting:
+ *
+ * Received PCEP Open message. Length:28.
+ *
+ * 20 01 00 1c 01 10 00 18 20 1e 78 03 00 10 00 04 00 00 00 05 00 1a 00 04 00 00 00 b4
+ *
+ */
+public class PCEPHexDumpParser {
+       private static final int MINIMAL_LENGTH = 4;
+       private static final Logger LOG = LoggerFactory.getLogger(PCEPHexDumpParser.class);
+       private static final String LENGTH = "LENGTH:";
+
+       private PCEPHexDumpParser() {
+
+       }
+
+       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(final InputStream is) throws IOException {
+               Preconditions.checkNotNull(is);
+               try (InputStreamReader isr = new InputStreamReader(is)) {
+                       return parseMessages(CharStreams.toString(isr));
+               } finally {
+                       is.close();
+               }
+       }
+
+       private static List<byte[]> parseMessages(final String c) {
+               final String content = clearWhiteSpaceToUpper(c);
+
+               final List<byte[]> messages = Lists.newLinkedList();
+               int idx = content.indexOf(LENGTH, 0);
+               while (idx > -1) {
+                       // next chars are final length, ending with '.'
+                       final int lengthIdx = idx + LENGTH.length();
+                       final int messageIdx = content.indexOf('.', lengthIdx);
+
+                       final int length = Integer.valueOf(content.substring(lengthIdx, messageIdx));
+                       final int messageEndIdx = idx + length * 2;
+
+                       // Assert that message is longer than minimum 4(header.length == 4)
+                       // If length in PCEP 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);
+
+                       final String hexMessage = content.substring(idx, messageEndIdx);
+                       byte[] message = null;
+                       try {
+                               message = Hex.decodeHex(hexMessage.toCharArray());
+                       } catch (final DecoderException e) {
+                               new RuntimeException(e);
+                       }
+                       messages.add(message);
+                       idx = messageEndIdx;
+                       idx = content.indexOf(LENGTH, idx);
+               }
+               LOG.info("Succesfully extracted {} messages", messages.size());
+               return messages;
+       }
+
+       private static String clearWhiteSpaceToUpper(final String line) {
+               return line.replaceAll("\\s", "").toUpperCase();
+       }
+}
diff --git a/util/src/test/java/org/opendaylight/protocol/util/PCEPHexDumpParserTest.java b/util/src/test/java/org/opendaylight/protocol/util/PCEPHexDumpParserTest.java
new file mode 100644 (file)
index 0000000..56601e0
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.List;
+
+import org.junit.Test;
+
+public class PCEPHexDumpParserTest {
+
+       public static final String hexDumpFileName = "/pcep-hex.txt";
+       private final int expectedSize = 6;
+
+       @Test
+       public void testParsing() throws Exception {
+               final List<byte[]> result = PCEPHexDumpParser.parseMessages(getClass().getResourceAsStream(PCEPHexDumpParserTest.hexDumpFileName));
+               assertEquals(this.expectedSize, result.size());
+       }
+
+       @Test
+       public void testParsingInvalidFile() throws Exception {
+               try {
+                       PCEPHexDumpParser.parseMessages(new File("bad file name"));
+                       fail("Exception should have occured.");
+               } catch (final FileNotFoundException e) {
+                       assertThat(e.getMessage(), containsString("bad file name (No such file or directory)"));
+               }
+       }
+}
diff --git a/util/src/test/resources/pcep-hex.txt b/util/src/test/resources/pcep-hex.txt
new file mode 100644 (file)
index 0000000..434a46c
--- /dev/null
@@ -0,0 +1,37 @@
+Received PCEP Open message. Length:28.
+
+20 01 00 1c 01 10 00 18  20 1e 78 03 00 10 00 04
+00 00 00 05 00 1a 00 04  00 00 00 b4
+
+Received PCEP Keepalive message. Length:4.
+
+20 02 00 04
+
+Received PCEPReport message. Length:12.
+
+20 0a 00 0c 20 10 00 08  00 00 00 00
+
+Received PCEPReport message. Length:56.
+
+20 0a 00 38 20 10 00 34  00 00 50 01 00 11 00 28
+74 75 6e 6e 65 6c 5f 66  72 6f 6d 5f 4f 66 2d 39
+6b 2d 30 32 5f 74 6f 5f  4f 66 2d 39 6b 2d 30 33
+4f 66 2d 39 6b 2d 30 32
+
+Received PCEPReport message. Length:120.
+
+20 0a 00 78 20 10 00 44  00 00 50 05 00 11 00 28
+74 75 6e 6e 65 6c 5f 66  72 6f 6d 5f 4f 66 2d 39
+6b 2d 30 32 5f 74 6f 5f  4f 66 2d 39 6b 2d 30 33
+4f 66 2d 39 6b 2d 30 32  00 12 00 0c 2a 2a 2a 2a
+00 00 00 04 2a 2a 2a 2a  07 10 00 14 01 08 c6 14
+a0 2b 20 00 01 08 2b 2b  2b 2b 20 00 09 10 00 14
+00 00 00 00 00 00 00 00  00 00 00 00 07 07 00 00
+05 20 00 08 00 00 00 00
+
+Received PCEPReport message. Length:56.
+
+20 0a 00 38 20 10 00 34  00 00 50 0c 00 11 00 28
+74 75 6e 6e 65 6c 5f 66  72 6f 6d 5f 4f 66 2d 39
+6b 2d 30 32 5f 74 6f 5f  4f 66 2d 39 6b 2d 30 33
+4f 66 2d 39 6b 2d 30 32