Added cleanup tlv to session proposal. 41/5141/5
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 5 Feb 2014 23:03:27 +0000 (00:03 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 6 Feb 2014 21:12:19 +0000 (21:12 +0000)
Change-Id: Ia1bd0df7370a0ec776c8ee78bfd3e982c7d37a6e
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/InitiatedActivator.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/PCEPOpenObjectParser.java [new file with mode: 0644]
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02SessionProposalFactory.java
pcep/ietf-stateful02/src/main/yang/odl-pcep-crabbe-initiated00.yang
pcep/ietf-stateful02/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPObjectParserTest.java
pcep/ietf-stateful02/src/test/resources/PCEPOpenObject1.bin

index c353dc0eb98f79ea3ddb295422bab10b03416929..65814acdb07260759305b9e439f15af1bdce8ac5 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActi
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Pcinitiate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.lsp.cleanup.tlv.LspCleanup;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 
 public class InitiatedActivator extends AbstractPCEPExtensionProviderActivator {
        @Override
@@ -25,6 +26,10 @@ public class InitiatedActivator extends AbstractPCEPExtensionProviderActivator {
                                new PcinitiateMessageParser(context.getObjectHandlerRegistry())));
                regs.add(context.registerMessageSerializer(Pcinitiate.class, new PcinitiateMessageParser(context.getObjectHandlerRegistry())));
 
+               regs.add(context.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE,
+                               new PCEPOpenObjectParser(context.getTlvHandlerRegistry())));
+               regs.add(context.registerObjectSerializer(Open.class, new PCEPOpenObjectParser(context.getTlvHandlerRegistry())));
+
                regs.add(context.registerTlvParser(LSPCleanupTlvParser.TYPE, new LSPCleanupTlvParser()));
                regs.add(context.registerTlvSerializer(LspCleanup.class, new LSPCleanupTlvParser()));
 
diff --git a/pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/PCEPOpenObjectParser.java b/pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/PCEPOpenObjectParser.java
new file mode 100644 (file)
index 0000000..8db8048
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.crabbe.initiated00;
+
+import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.UnknownObject;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.lsp.cleanup.tlv.LspCleanup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList;
+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.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.primitives.UnsignedBytes;
+
+/**
+ * Parser for {@link Open}
+ */
+public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuilder> {
+       private static final Logger LOG = LoggerFactory.getLogger(PCEPOpenObjectParser.class);
+
+       public static final int CLASS = 1;
+
+       public static final int TYPE = 1;
+
+       /*
+        * lengths of fields in bytes
+        */
+       private static final int VER_FLAGS_MF_LENGTH = 1;
+       private static final int KEEPALIVE_F_LENGTH = 1;
+       private static final int DEAD_TIMER_LENGTH = 1;
+       private static final int SID_F_LENGTH = 1;
+
+       /*
+        * lengths of subfields inside multi-field in bits
+        */
+       private static final int VERSION_SF_LENGTH = 3;
+
+       /*
+        * offsets of field in bytes
+        */
+       private static final int VER_FLAGS_MF_OFFSET = 0;
+       private static final int KEEPALIVE_F_OFFSET = VER_FLAGS_MF_OFFSET + VER_FLAGS_MF_LENGTH;
+       private static final int DEAD_TIMER_OFFSET = KEEPALIVE_F_OFFSET + KEEPALIVE_F_LENGTH;
+       private static final int SID_F_OFFSET = DEAD_TIMER_OFFSET + DEAD_TIMER_LENGTH;
+       private static final int TLVS_OFFSET = SID_F_OFFSET + SID_F_LENGTH;
+
+       /*
+        * offsets of subfields inside multi-field in bits
+        */
+       private static final int VERSION_SF_OFFSET = 0;
+
+       private static final int PCEP_VERSION = 1;
+
+       public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+               super(tlvReg);
+       }
+
+       @Override
+       public Object parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
+               if (bytes == null || bytes.length == 0) {
+                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+               }
+               final int versionValue = ByteArray.copyBitsRange(bytes[VER_FLAGS_MF_OFFSET], VERSION_SF_OFFSET, VERSION_SF_LENGTH);
+
+               final OpenBuilder builder = new OpenBuilder();
+               builder.setVersion(new ProtocolVersion((short) versionValue));
+               builder.setProcessingRule(header.isProcessingRule());
+               builder.setIgnore(header.isIgnore());
+               builder.setDeadTimer((short) UnsignedBytes.toInt(bytes[DEAD_TIMER_OFFSET]));
+               builder.setKeepalive((short) UnsignedBytes.toInt(bytes[KEEPALIVE_F_OFFSET]));
+               builder.setSessionId((short) UnsignedBytes.toInt(bytes[SID_F_OFFSET]));
+
+               final TlvsBuilder tbuilder = new TlvsBuilder();
+               parseTlvs(tbuilder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
+               builder.setTlvs(tbuilder.build());
+
+               final Open obj = builder.build();
+               if (versionValue != PCEP_VERSION) {
+                       // TODO: Should we move this check into the negotiator
+                       LOG.debug("Unsupported PCEP version {}", versionValue);
+                       return new UnknownObject(PCEPErrors.PCEP_VERSION_NOT_SUPPORTED, obj);
+               }
+
+               return obj;
+       }
+
+       @Override
+       public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
+               final Tlvs2Builder statefulBuilder = new Tlvs2Builder();
+               if (tbuilder.getAugmentation(Tlvs2.class) != null) {
+                       final Tlvs2 t = tbuilder.getAugmentation(Tlvs2.class);
+                       if (t.getStateful() != null) {
+                               statefulBuilder.setStateful(t.getStateful());
+                       }
+                       if (t.getNodeIdentifier() != null) {
+                               statefulBuilder.setNodeIdentifier(t.getNodeIdentifier());
+                       }
+               }
+               final Tlvs1Builder cleanupBuilder = new Tlvs1Builder();
+               if (tbuilder.getAugmentation(Tlvs1.class) != null) {
+                       final Tlvs1 t = tbuilder.getAugmentation(Tlvs1.class);
+                       if (t.getLspCleanup() != null) {
+                               cleanupBuilder.setLspCleanup(t.getLspCleanup());
+                       }
+               }
+               if (tlv instanceof OfList) {
+                       tbuilder.setOfList((OfList) tlv);
+               } else if (tlv instanceof Stateful) {
+                       statefulBuilder.setStateful((Stateful) tlv);
+               } else if (tlv instanceof NodeIdentifier) {
+                       statefulBuilder.setNodeIdentifier((NodeIdentifier) tlv);
+               } else if (tlv instanceof LspCleanup) {
+                       cleanupBuilder.setLspCleanup((LspCleanup) tlv);
+               }
+               tbuilder.addAugmentation(Tlvs2.class, statefulBuilder.build());
+               tbuilder.addAugmentation(Tlvs1.class, cleanupBuilder.build());
+       }
+
+       @Override
+       public byte[] serializeObject(final Object object) {
+               if (!(object instanceof Open)) {
+                       throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed OpenObject.");
+               }
+               final Open open = (Open) object;
+
+               final byte versionFlagMF = (byte) (PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH));
+
+               final byte[] tlvs = serializeTlvs(open.getTlvs());
+
+               final byte[] bytes = new byte[TLVS_OFFSET + tlvs.length + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+
+               bytes[VER_FLAGS_MF_OFFSET] = versionFlagMF;
+               bytes[KEEPALIVE_F_OFFSET] = UnsignedBytes.checkedCast(open.getKeepalive());
+               bytes[DEAD_TIMER_OFFSET] = UnsignedBytes.checkedCast(open.getDeadTimer());
+               bytes[SID_F_OFFSET] = UnsignedBytes.checkedCast(open.getSessionId());
+               if (tlvs.length != 0) {
+                       ByteArray.copyWhole(tlvs, bytes, TLVS_OFFSET);
+               }
+               return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), bytes);
+       }
+
+       public byte[] serializeTlvs(final Tlvs tlvs) {
+               if (tlvs == null) {
+                       return new byte[0];
+               }
+               int finalLength = 0;
+               byte[] ofListBytes = null;
+               byte[] statefulBytes = null;
+               byte[] nodeIdBytes = null;
+               byte[] cleanupBytes = null;
+               if (tlvs.getOfList() != null) {
+                       ofListBytes = serializeTlv(tlvs.getOfList());
+                       finalLength += ofListBytes.length;
+               }
+               if (tlvs.getAugmentation(Tlvs2.class) != null) {
+                       final Tlvs2 statefulTlvs = tlvs.getAugmentation(Tlvs2.class);
+                       if (statefulTlvs.getStateful() != null) {
+                               statefulBytes = serializeTlv(statefulTlvs.getStateful());
+                               finalLength += statefulBytes.length;
+                       }
+                       if (statefulTlvs.getNodeIdentifier() != null) {
+                               nodeIdBytes = serializeTlv(statefulTlvs.getNodeIdentifier());
+                               finalLength += nodeIdBytes.length;
+                       }
+               }
+               if (tlvs.getAugmentation(Tlvs1.class) != null) {
+                       final Tlvs1 cleanupTlv = tlvs.getAugmentation(Tlvs1.class);
+                       if (cleanupTlv.getLspCleanup() != null) {
+                               cleanupBytes = serializeTlv(cleanupTlv.getLspCleanup());
+                               finalLength += cleanupBytes.length;
+                       }
+               }
+
+               int offset = 0;
+               final byte[] result = new byte[finalLength];
+               if (ofListBytes != null) {
+                       ByteArray.copyWhole(ofListBytes, result, offset);
+                       offset += ofListBytes.length;
+               }
+               if (statefulBytes != null) {
+                       ByteArray.copyWhole(statefulBytes, result, offset);
+                       offset += statefulBytes.length;
+               }
+               if (nodeIdBytes != null) {
+                       ByteArray.copyWhole(nodeIdBytes, result, offset);
+                       offset += nodeIdBytes.length;
+               }
+               if (cleanupBytes != null) {
+                       ByteArray.copyWhole(cleanupBytes, result, offset);
+                       offset += cleanupBytes.length;
+               }
+               return result;
+       }
+
+       @Override
+       public int getObjectType() {
+               return TYPE;
+       }
+
+       @Override
+       public int getObjectClass() {
+               return CLASS;
+       }
+}
index 83727032ba267e9da5d7372405f689de83047272..1d513a1b708dc0e854fb8631149bd0c8d19d913d 100644 (file)
@@ -12,6 +12,9 @@ import java.net.InetSocketAddress;
 import org.opendaylight.protocol.pcep.spi.AbstractPCEPSessionProposalFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.lsp.cleanup.tlv.LspCleanupBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.StatefulBuilder;
@@ -37,6 +40,7 @@ public class Stateful02SessionProposalFactory extends AbstractPCEPSessionProposa
                                        new Tlvs2Builder().setStateful(
                                                        new StatefulBuilder().setLspUpdateCapability(this.active).addAugmentation(Stateful1.class,
                                                                        new Stateful1Builder().setInitiation(this.instant).build()).build()).build()).build();
+                       builder.addAugmentation(Tlvs1.class, new Tlvs1Builder().setLspCleanup(new LspCleanupBuilder().setTimeout(180L).build()).build());
                }
        }
 
index bb9c4d9bc79055d71bdc0970fb29302faec10c6a..e46590f2ded748d9dd93303179b8a78eafe1e40f 100644 (file)
@@ -59,6 +59,10 @@ module odl-pcep-crabbe-initiated00 {
                        }
                }
        }
+       
+       augment "/msg:open/msg:open-message/msg:open/msg:tlvs" {
+               uses lsp-cleanup-tlv;
+       }
 
        augment "/msg:open/msg:open-message/msg:open/msg:tlvs/stateful02:stateful" {
                leaf initiation {
index 757fd69b06a3ec23a50fa47969d1170567b010ad..473dbb07626fc41c7418a854e53ccaccb8ae6e32 100644 (file)
@@ -20,6 +20,9 @@ import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProvide
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.lsp.cleanup.tlv.LspCleanupBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
@@ -55,8 +58,11 @@ public class PCEPObjectParserTest {
                final Tlvs2Builder statBuilder = new Tlvs2Builder();
                statBuilder.setStateful(tlv1);
 
+               final Tlvs1Builder cleanupBuilder = new Tlvs1Builder();
+               cleanupBuilder.setLspCleanup(new LspCleanupBuilder().setTimeout(180L).build());
+
                builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().addAugmentation(
-                               Tlvs2.class, statBuilder.build()).build());
+                               Tlvs2.class, statBuilder.build()).addAugmentation(Tlvs1.class, cleanupBuilder.build()).build());
 
                // FIXME: enable once the registry is rewritten
                // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
index 9d1152bdb752b4d6587562ff49e6b09657dd6aee..5ff89be3f24d9128206b4a2a8510422d2cd38413 100644 (file)
Binary files a/pcep/ietf-stateful02/src/test/resources/PCEPOpenObject1.bin and b/pcep/ietf-stateful02/src/test/resources/PCEPOpenObject1.bin differ