Code clean up
[bgpcep.git] / bgp / mvpn / src / main / java / org / opendaylight / protocol / bgp / mvpn / impl / nlri / SourceActiveADHandler.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 io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.bgp.concepts.IpAddressUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.NlriType;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.MvpnChoice;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.mvpn.choice.SourceActiveADCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.mvpn.choice.SourceActiveADCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.source.active.a.d.grouping.SourceActiveAD;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.source.active.a.d.grouping.SourceActiveADBuilder;
20
21 /**
22  * https://tools.ietf.org/html/rfc6514#section-4.5.
23  *
24  * @author Claudio D. Gasparini
25  */
26 public final class SourceActiveADHandler extends AbstractMvpnNlri<SourceActiveADCase> {
27     @Override
28     public int getType() {
29         return NlriType.SourceActiveAD.getIntValue();
30     }
31
32     @Override
33     public SourceActiveADCase parseMvpn(final ByteBuf buffer) {
34         final SourceActiveADBuilder builder = new SourceActiveADBuilder(parseRDMulticastSource(buffer));
35         builder.setMulticastGroup(IpAddressUtil.addressForByteBuf(buffer));
36         return new SourceActiveADCaseBuilder().setSourceActiveAD(builder.build()).build();
37     }
38
39
40     @Override
41     protected ByteBuf serializeBody(final SourceActiveADCase mvpn) {
42         final SourceActiveAD route = mvpn.getSourceActiveAD();
43         final ByteBuf nlriByteBuf = Unpooled.buffer();
44         serializeRDMulticastSource(route, nlriByteBuf);
45         nlriByteBuf.writeBytes(IpAddressUtil.bytesFor(route.getMulticastGroup()));
46         return nlriByteBuf;
47     }
48
49     @Override
50     public Class<? extends MvpnChoice> getClazz() {
51         return SourceActiveADCase.class;
52     }
53 }