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