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,
45 "Wrong instance of Message. Passed instance of %s. Need Pcmonreq.", message.getClass());
46 final PcreqMessage msg = ((Pcmonreq) message).getPcreqMessage();
47 Preconditions.checkArgument(msg.getMonitoringRequest() != null, "MONITORING object MUST be present.");
48 final ByteBuf buffer = Unpooled.buffer();
49 serializeMonitoringRequest(msg.getMonitoringRequest(), buffer);
50 if (msg.getSvec() != null) {
51 serializeSvec(msg, buffer);
53 if (msg.getRequests() != null) {
54 serializeRequest(msg, buffer);
56 MessageUtil.formatMessage(TYPE, buffer, out);
60 protected Message validate(final List<Object> objects, final List<Message> errors)
61 throws PCEPDeserializerException {
62 Preconditions.checkArgument(objects != null, "Passed list can't be null.");
63 if (objects.isEmpty()) {
64 throw new PCEPDeserializerException("Pcmonreq message cannot be empty.");
66 final MonitoringRequest monReq = getMonitoring(objects);
68 errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.empty()));
70 final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder().setMonitoringRequest(monReq);
71 final List<Svec> svecs = getSvecs(objects);
72 if (!svecs.isEmpty()) {
73 mBuilder.setSvec(svecs);
75 final List<Requests> requests = getRequests(objects, errors);
76 if (requests != null && !requests.isEmpty()) {
77 mBuilder.setRequests(requests);
79 if (!objects.isEmpty()) {
80 throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
82 return new PcmonreqBuilder().setPcreqMessage(mBuilder.build()).build();