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.parser.message;
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import java.util.List;
14 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
15 import org.opendaylight.protocol.pcep.spi.MessageUtil;
16 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OpenMessage;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
26 * Parser for {@link OpenMessage}.
28 public class PCEPOpenMessageParser extends AbstractMessageParser {
30 public static final int TYPE = 1;
32 public PCEPOpenMessageParser(final ObjectRegistry registry) {
37 public void serializeMessage(final Message message, final ByteBuf out) {
38 Preconditions.checkArgument(message instanceof OpenMessage,
39 "Wrong instance of Message. Passed instance of %s. Need OpenMessage.", message.getClass());
40 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message
41 .OpenMessage open = ((OpenMessage) message).getOpenMessage();
42 Preconditions.checkArgument(open.getOpen() != null, "Open Object must be present in Open Message.");
43 final ByteBuf buffer = Unpooled.buffer();
44 serializeObject(open.getOpen(), buffer);
45 MessageUtil.formatMessage(TYPE, buffer, out);
49 protected org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open validate(
50 final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
51 Preconditions.checkArgument(objects != null, "Passed list can't be null.");
53 if (objects.isEmpty() || !(objects.get(0) instanceof Open)) {
54 throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
57 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message
58 .OpenMessage msg = new OpenMessageBuilder().setOpen((Open) objects.get(0)).build();
62 if (!objects.isEmpty()) {
63 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
66 return new OpenBuilder().setOpenMessage(msg).build();