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 java.util.Queue;
17 import org.opendaylight.protocol.pcep.spi.MessageUtil;
18 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
19 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
20 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcmonreq;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonreqBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.PcreqMessage;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.PcreqMessageBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.MonitoringRequest;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Svec;
32 * Parser for {@link Pcmonreq}.
33 * @see <a href="https://tools.ietf.org/html/rfc5886#section-3.1">Monitoring Request Message</a>
35 public class PCEPMonitoringRequestMessageParser extends PCEPRequestMessageParser {
37 public static final int TYPE = 8;
39 public PCEPMonitoringRequestMessageParser(final ObjectRegistry registry) {
44 public void serializeMessage(final Message message, final ByteBuf out) {
45 Preconditions.checkArgument(message instanceof Pcmonreq,
46 "Wrong instance of Message. Passed instance of %s. Need Pcmonreq.", message.getClass());
47 final PcreqMessage msg = ((Pcmonreq) message).getPcreqMessage();
48 Preconditions.checkArgument(msg.getMonitoringRequest() != null, "MONITORING object MUST be present.");
49 final ByteBuf buffer = Unpooled.buffer();
50 serializeMonitoringRequest(msg.getMonitoringRequest(), buffer);
51 if (msg.getSvec() != null) {
52 serializeSvec(msg, buffer);
54 if (msg.getRequests() != null) {
55 serializeRequest(msg, buffer);
57 MessageUtil.formatMessage(TYPE, buffer, out);
61 protected Message validate(final Queue<Object> objects, final List<Message> errors)
62 throws PCEPDeserializerException {
63 Preconditions.checkArgument(objects != null, "Passed list can't be null.");
64 if (objects.isEmpty()) {
65 throw new PCEPDeserializerException("Pcmonreq message cannot be empty.");
67 final MonitoringRequest monReq = getMonitoring(objects);
69 errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.empty()));
71 final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder().setMonitoringRequest(monReq);
72 final List<Svec> svecs = getSvecs(objects);
73 if (!svecs.isEmpty()) {
74 mBuilder.setSvec(svecs);
76 final List<Requests> requests = getRequests(objects, errors);
77 if (requests != null && !requests.isEmpty()) {
78 mBuilder.setRequests(requests);
80 if (!objects.isEmpty()) {
81 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
83 return new PcmonreqBuilder().setPcreqMessage(mBuilder.build()).build();