2 * Copyright (c) 2015 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.bmp.parser.message;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.base.Preconditions;
14 import io.netty.buffer.ByteBuf;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
18 import org.opendaylight.protocol.bmp.spi.parser.AbstractBmpPerPeerMessageParser;
19 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateMessage;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.RouteMonitoringMessage;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.RouteMonitoringMessageBuilder;
24 import org.opendaylight.yangtools.yang.binding.Notification;
26 public class RouteMonitoringMessageHandler extends AbstractBmpPerPeerMessageParser<RouteMonitoringMessageBuilder> {
28 private static final int MESSAGE_TYPE = 0;
29 private final MessageRegistry msgRegistry;
31 public RouteMonitoringMessageHandler(final MessageRegistry bgpMssageRegistry) {
32 super(bgpMssageRegistry);
33 msgRegistry = getBgpMessageRegistry();
37 public void serializeMessageBody(final Notification<?> message, final ByteBuf buffer) {
38 super.serializeMessageBody(message, buffer);
39 Preconditions.checkArgument(message instanceof RouteMonitoringMessage,
40 "An instance of RouteMonitoringMessage is required");
41 final RouteMonitoringMessage routeMonitor = (RouteMonitoringMessage) message;
42 msgRegistry.serializeMessage(new UpdateBuilder(routeMonitor.getUpdate()).build(), buffer);
46 public RouteMonitoringMessage parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
47 final RouteMonitoringMessageBuilder routeMonitor = new RouteMonitoringMessageBuilder()
48 .setPeerHeader(parsePerPeerHeader(bytes));
50 final Notification<?> message = msgRegistry.parseMessage(bytes, null);
51 requireNonNull(message, "UpdateMessage may not be null");
52 Preconditions.checkArgument(message instanceof UpdateMessage,
53 "An instance of UpdateMessage is required");
54 final UpdateMessage updateMessage = (UpdateMessage) message;
55 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.route
56 .monitoring.message.Update update = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
57 .ns.yang.bmp.message.rev200120.route.monitoring.message.UpdateBuilder(updateMessage).build();
58 routeMonitor.setUpdate(update);
59 } catch (final BGPDocumentedException | BGPParsingException e) {
60 throw new BmpDeserializationException("Error while parsing Update Message.", e);
63 return routeMonitor.build();
67 public int getBmpMessageType() {