2 * Copyright (c) 2018 AT&T Intellectual Property. 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.mvpn.impl.nlri;
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.bgp.concepts.IpAddressUtil;
15 import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.NlriType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.intra.as.i.pmsi.a.d.grouping.IntraAsIPmsiAD;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.intra.as.i.pmsi.a.d.grouping.IntraAsIPmsiADBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.MvpnChoice;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.mvpn.choice.IntraAsIPmsiADCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.mvpn.choice.IntraAsIPmsiADCaseBuilder;
24 * https://tools.ietf.org/html/rfc6514#section-4.1.
26 * @author Claudio D. Gasparini
28 public final class IntraAsIPmsiADHandler extends AbstractMvpnNlri<IntraAsIPmsiADCase> {
30 private static final int IPV4_CONTENT_LENGTH = 12;
31 private static final int IPV6_CONTENT_LENGTH = 24;
34 public int getType() {
35 return NlriType.IntraAsIPmsiAD.getIntValue();
39 public IntraAsIPmsiADCase parseMvpn(final ByteBuf buffer) {
40 Preconditions.checkArgument(buffer.readableBytes() == IPV4_CONTENT_LENGTH
41 || buffer.readableBytes() == IPV6_CONTENT_LENGTH,
42 "Wrong length of array of bytes. Passed: %s ;", buffer);
43 return new IntraAsIPmsiADCaseBuilder()
44 .setIntraAsIPmsiAD(new IntraAsIPmsiADBuilder()
45 .setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(buffer))
46 .setOrigRouteIp(IpAddressUtil.addressForByteBufWOLength(buffer))
52 protected ByteBuf serializeBody(final IntraAsIPmsiADCase mvpn) {
53 final IntraAsIPmsiAD route = mvpn.getIntraAsIPmsiAD();
54 final ByteBuf nlriByteBuf = Unpooled.buffer();
55 RouteDistinguisherUtil.serializeRouteDistinquisher(route.getRouteDistinguisher(), nlriByteBuf);
56 final ByteBuf orig = IpAddressUtil.bytesWOLengthFor(route.getOrigRouteIp());
57 Preconditions.checkArgument(orig.readableBytes() > 0);
58 nlriByteBuf.writeBytes(orig);
63 public Class<? extends MvpnChoice> getClazz() {
64 return IntraAsIPmsiADCase.class;