2 * Copyright (c) 2013 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.bgp.parser.impl.message;
10 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
17 import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
18 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.KeepaliveBuilder;
21 import org.opendaylight.yangtools.yang.binding.Notification;
23 public class BGPKeepAliveMessageParser implements MessageParser, MessageSerializer {
24 public static final int TYPE = 4;
25 private static final ByteBuf kaBytes = Unpooled.wrappedBuffer(MessageUtil.formatMessage(TYPE, new byte[0]));
26 private static final Keepalive msg = new KeepaliveBuilder().build();
29 public Keepalive parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
30 if (body.isReadable()) {
31 throw BGPDocumentedException.badMessageLength("Message length field not within valid range.", messageLength);
37 public void serializeMessage(final Notification message, ByteBuf bytes) {
38 Preconditions.checkArgument(message instanceof Keepalive);
39 kaBytes.markReaderIndex();
40 bytes.writeBytes(kaBytes);
41 kaBytes.resetReaderIndex();