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 static com.google.common.base.Preconditions.checkArgument;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.opendaylight.bgp.concepts.IpAddressUtil;
16 import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.NlriType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.intra.as.i.pmsi.a.d.grouping.IntraAsIPmsiAD;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.intra.as.i.pmsi.a.d.grouping.IntraAsIPmsiADBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.mvpn.mvpn.choice.IntraAsIPmsiADCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.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> {
29 private static final int IPV4_CONTENT_LENGTH = 12;
30 private static final int IPV6_CONTENT_LENGTH = 24;
32 public IntraAsIPmsiADHandler() {
33 super(IntraAsIPmsiADCase.class, NlriType.IntraAsIPmsiAD);
37 public IntraAsIPmsiADCase parseMvpn(final ByteBuf buffer) {
38 checkArgument(buffer.readableBytes() == IPV4_CONTENT_LENGTH || buffer.readableBytes() == IPV6_CONTENT_LENGTH,
39 "Wrong length of array of bytes. Passed: %s ;", buffer);
40 return new IntraAsIPmsiADCaseBuilder()
41 .setIntraAsIPmsiAD(new IntraAsIPmsiADBuilder()
42 .setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(buffer))
43 .setOrigRouteIp(IpAddressUtil.addressForByteBufWOLength(buffer))
49 protected ByteBuf serializeBody(final IntraAsIPmsiADCase mvpn) {
50 final IntraAsIPmsiAD route = mvpn.getIntraAsIPmsiAD();
51 final ByteBuf nlriByteBuf = Unpooled.buffer();
52 RouteDistinguisherUtil.serializeRouteDistinquisher(route.getRouteDistinguisher(), nlriByteBuf);
53 serializeAddress(route.getOrigRouteIp(), nlriByteBuf);