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.bgp.inet.codec.nexthop;
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.bgp.concepts.NextHopUtil;
14 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
15 import org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer;
16 import org.opendaylight.protocol.util.Ipv4Util;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.CNextHop;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
20 public final class Ipv4NextHopParserSerializer implements NextHopParserSerializer {
22 public CNextHop parseNextHop(final ByteBuf buffer) throws BGPParsingException {
23 Preconditions.checkArgument(buffer.readableBytes() == Ipv4Util.IP4_LENGTH,
24 "Length of byte array for NEXT_HOP should be %s, but is %s",
25 buffer.readableBytes(), Ipv4Util.IP4_LENGTH);
26 return NextHopUtil.parseNextHop(buffer);
30 public void serializeNextHop(final CNextHop nextHop, final ByteBuf byteAggregator) {
31 Preconditions.checkArgument(nextHop instanceof Ipv4NextHopCase,
32 "cNextHop is not a Ipv4 NextHop object.");
33 NextHopUtil.serializeNextHop(nextHop, byteAggregator);