2 * Copyright (c) 2014 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
9 package org.opendaylight.protocol.pcep.parser.message;
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.util.List;
15 import java.util.Optional;
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.protocol.pcep.spi.PCEPErrors;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcmonreq;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonreqBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.PcreqMessage;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.PcreqMessageBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.MonitoringRequest;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Svec;
31 * Parser for {@link Pcmonreq}
32 * @see <a href="https://tools.ietf.org/html/rfc5886#section-3.1">Monitoring Request Message</a>
34 public class PCEPMonitoringRequestMessageParser extends PCEPRequestMessageParser {
36 public static final int TYPE = 8;
38 public PCEPMonitoringRequestMessageParser(final ObjectRegistry registry) {
43 public void serializeMessage(final Message message, final ByteBuf out) {
44 Preconditions.checkArgument(message instanceof Pcmonreq, "Wrong instance of Message. Passed instance of %s. Need Pcmonreq.", message.getClass());
45 final PcreqMessage msg = ((Pcmonreq) message).getPcreqMessage();
46 Preconditions.checkArgument(msg.getMonitoringRequest() != null, "MONITORING object MUST be present.");
47 final ByteBuf buffer = Unpooled.buffer();
48 serializeMonitoringRequest(msg.getMonitoringRequest(), buffer);
49 if (msg.getSvec() != null) {
50 serializeSvec(msg, buffer);
52 if (msg.getRequests() != null) {
53 serializeRequest(msg, buffer);
55 MessageUtil.formatMessage(TYPE, buffer, out);
59 protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
60 Preconditions.checkArgument(objects != null, "Passed list can't be null.");
61 if (objects.isEmpty()) {
62 throw new PCEPDeserializerException("Pcmonreq message cannot be empty.");
64 final MonitoringRequest monReq = getMonitoring(objects);
66 errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.empty()));
68 final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder();
69 mBuilder.setMonitoringRequest(monReq);
70 final List<Svec> svecs = getSvecs(objects);
71 if (!svecs.isEmpty()) {
72 mBuilder.setSvec(svecs);
74 final List<Requests> requests = getRequests(objects, errors);
75 if (requests != null && !requests.isEmpty()) {
76 mBuilder.setRequests(requests);
78 if (!objects.isEmpty()) {
79 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
81 return new PcmonreqBuilder().setPcreqMessage(mBuilder.build()).build();