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 io.netty.buffer.ByteBuf;
11 import io.netty.buffer.Unpooled;
13 import java.util.List;
15 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
16 import org.opendaylight.protocol.pcep.spi.MessageUtil;
17 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
18 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
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.close.message.CCloseMessage;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
29 * Parser for {@link CloseMessage}
31 public class PCEPCloseMessageParser extends AbstractMessageParser {
33 public static final int TYPE = 7;
35 public PCEPCloseMessageParser(final ObjectRegistry registry) {
40 public void serializeMessage(final Message message, final ByteBuf out) {
41 if (!(message instanceof CloseMessage)) {
42 throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass()
43 + ". Nedded CloseMessage.");
45 final CCloseMessage close = ((CloseMessage) message).getCCloseMessage();
47 if (close.getCClose() == null) {
48 throw new IllegalArgumentException("Close Object must be present in Close Message.");
50 ByteBuf buffer = Unpooled.buffer();
51 buffer.writeBytes(serializeObject(close.getCClose()));
52 MessageUtil.formatMessage(TYPE, buffer, out);
56 protected Close validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
57 if (objects == null) {
58 throw new IllegalArgumentException("Passed list can't be null.");
60 if (objects.isEmpty() || !(objects.get(0) instanceof CClose)) {
61 throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
63 final Object o = objects.get(0);
64 final CCloseMessage msg = new CCloseMessageBuilder().setCClose((CClose) o).build();
66 if (!objects.isEmpty()) {
67 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
69 return new CloseBuilder().setCCloseMessage(msg).build();
73 public int getMessageType() {