Bug 2231 - Paerser/Serializer for startTLS message 70/15470/2
authorLadislav Borak <lborak@cisco.com>
Wed, 18 Feb 2015 16:47:03 +0000 (17:47 +0100)
committerLadislav Borak <lborak@cisco.com>
Thu, 19 Feb 2015 10:08:50 +0000 (11:08 +0100)
Change-Id: I231327deb2fcb9b794b9b791d061c978aeb15190
Signed-off-by: Ladislav Borak <lborak@cisco.com>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPStartTLSMessageParser.java [new file with mode: 0644]

diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPStartTLSMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPStartTLSMessageParser.java
new file mode 100644 (file)
index 0000000..bb225eb
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl.message;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
+import org.opendaylight.protocol.pcep.spi.MessageUtil;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.StarttlsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.start.tls.message.StartTlsMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.start.tls.message.StartTlsMessageBuilder;
+
+public class PCEPStartTLSMessageParser extends AbstractMessageParser {
+
+    public static final int TYPE = 8;
+
+    protected PCEPStartTLSMessageParser(final ObjectRegistry registry) {
+        super(registry);
+    }
+
+    @Override
+    public void serializeMessage(final Message message, final ByteBuf out) {
+        Preconditions.checkArgument(message instanceof StartTlsMessage, "Wrong instance of Message. Passed instance of %s. Need StartTlsMessage.", message.getClass());
+        MessageUtil.formatMessage(TYPE, Unpooled.EMPTY_BUFFER, out);
+    }
+
+    @Override
+    protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
+        if (objects != null && !objects.isEmpty()) {
+            throw new PCEPDeserializerException("StartTLS message should not contain any objects.");
+        }
+        return new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build();
+    }
+}