2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.impl.message;
10 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
15 import java.util.List;
17 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
18 import org.opendaylight.protocol.pcep.spi.MessageUtil;
19 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
20 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
29 * Parser for {@link OpenMessage}
31 public class PCEPOpenMessageParser extends AbstractMessageParser {
33 public static final int TYPE = 1;
35 public PCEPOpenMessageParser(final ObjectRegistry registry) {
40 public void serializeMessage(final Message message, final ByteBuf out) {
41 Preconditions.checkArgument(message instanceof OpenMessage, "Wrong instance of Message. Passed instance of %s. Need OpenMessage.", message.getClass());
42 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage open = ((OpenMessage) message).getOpenMessage();
44 if (open.getOpen() == null) {
45 throw new IllegalArgumentException("Open Object must be present in Open Message.");
47 ByteBuf buffer = Unpooled.buffer();
48 serializeObject(open.getOpen(), buffer);
49 MessageUtil.formatMessage(TYPE, buffer, out);
53 protected org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open validate(
54 final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
55 if (objects == null) {
56 throw new IllegalArgumentException("Passed list can't be null.");
59 if (objects.isEmpty() || !(objects.get(0) instanceof Open)) {
60 throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
63 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage msg = new OpenMessageBuilder().setOpen(
64 (Open) objects.get(0)).build();
68 if (!objects.isEmpty()) {
69 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
72 return new OpenBuilder().setOpenMessage(msg).build();