2e080c246e6d7cd76046c68ad310df30bad5b6a6
[bgpcep.git] / bgp / mvpn / src / main / java / org / opendaylight / protocol / bgp / mvpn / impl / nlri / InterASIPmsiADHandler.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.mvpn.impl.nlri;
10
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.RouteDistinguisherUtil;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
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.inter.as.i.pmsi.a.d.grouping.InterAsIPmsiAD;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.inter.as.i.pmsi.a.d.grouping.InterAsIPmsiADBuilder;
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.InterAsIPmsiADCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.mvpn.choice.InterAsIPmsiADCaseBuilder;
22
23 /**
24  * https://tools.ietf.org/html/rfc6514#section-4.2 .
25  *
26  * @author Claudio D. Gasparini
27  */
28 public final class InterASIPmsiADHandler extends AbstractMvpnNlri<InterAsIPmsiADCase> {
29     private static final int CONTENT_LENGTH = 12;
30
31     @Override
32     public int getType() {
33         return NlriType.InterAsIPmsiAD.getIntValue();
34     }
35
36     @Override
37     public InterAsIPmsiADCase parseMvpn(final ByteBuf buffer) {
38         Preconditions.checkArgument(buffer.readableBytes() == CONTENT_LENGTH,
39                 "Wrong length of array of bytes. Passed: %s ;", buffer);
40         return new InterAsIPmsiADCaseBuilder()
41                 .setInterAsIPmsiAD(new InterAsIPmsiADBuilder()
42                         .setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(buffer))
43                         .setSourceAs(new AsNumber(buffer.readUnsignedInt()))
44                         .build())
45                 .build();
46     }
47
48     @Override
49     protected ByteBuf serializeBody(final InterAsIPmsiADCase mvpn) {
50         final InterAsIPmsiAD route = mvpn.getInterAsIPmsiAD();
51         final ByteBuf nlriByteBuf = Unpooled.buffer();
52         RouteDistinguisherUtil.serializeRouteDistinquisher(route.getRouteDistinguisher(), nlriByteBuf);
53         nlriByteBuf.writeInt(route.getSourceAs().getValue().intValue());
54         return nlriByteBuf;
55     }
56
57     @Override
58     public Class<? extends MvpnChoice> getClazz() {
59         return InterAsIPmsiADCase.class;
60     }
61 }