Eliminate use of ByteBufWriteUtil from mvpn
[bgpcep.git] / bgp / extensions / mvpn / src / main / java / org / opendaylight / protocol / bgp / mvpn / impl / attributes / tunnel / identifier / RsvpTeP2MpLspParser.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  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 package org.opendaylight.protocol.bgp.mvpn.impl.attributes.tunnel.identifier;
9
10 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.tunnel.identifier.PAddressPMulticastGroupUtil.parseIpAddress;
11 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.tunnel.identifier.PAddressPMulticastGroupUtil.serializeIpAddress;
12
13 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.protocol.bgp.mvpn.spi.attributes.tunnel.identifier.AbstractTunnelIdentifier;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.PmsiTunnelType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.TunnelIdentifier;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.RsvpTeP2mpLsp;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.RsvpTeP2mpLspBuilder;
19 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
20
21 public final class RsvpTeP2MpLspParser extends AbstractTunnelIdentifier<RsvpTeP2mpLsp> {
22     private static final int RESERVED = 2;
23
24     @Override
25     public Class<? extends TunnelIdentifier> getClazz() {
26         return RsvpTeP2mpLsp.class;
27     }
28
29     @Override
30     public int serialize(final RsvpTeP2mpLsp tunnelIdentifier, final ByteBuf buffer) {
31         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi
32                 .tunnel.tunnel.identifier.rsvp.te.p2mp.lsp
33                 .RsvpTeP2mpLsp rsvpTeP2mpLsp = tunnelIdentifier.getRsvpTeP2mpLsp();
34         ByteBufUtils.writeOrZero(buffer, rsvpTeP2mpLsp.getP2mpId());
35         buffer.writeZero(RESERVED);
36         ByteBufUtils.writeOrZero(buffer, rsvpTeP2mpLsp.getTunnelId());
37         serializeIpAddress(rsvpTeP2mpLsp.getExtendedTunnelId(), buffer);
38         return getType();
39     }
40
41     @Override
42     public RsvpTeP2mpLsp parse(final ByteBuf buffer) {
43         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel
44                 .pmsi.tunnel.tunnel.identifier.rsvp.te.p2mp.lsp.RsvpTeP2mpLspBuilder rsvpTeP2mpLps
45                 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi
46                 .tunnel.pmsi.tunnel.tunnel.identifier.rsvp.te.p2mp.lsp.RsvpTeP2mpLspBuilder();
47         rsvpTeP2mpLps.setP2mpId(ByteBufUtils.readUint32(buffer));
48         buffer.skipBytes(RESERVED);
49         rsvpTeP2mpLps.setTunnelId(ByteBufUtils.readUint16(buffer));
50         final int ipLength = buffer.readableBytes();
51         rsvpTeP2mpLps.setExtendedTunnelId(parseIpAddress(ipLength, buffer));
52         return new RsvpTeP2mpLspBuilder().setRsvpTeP2mpLsp(rsvpTeP2mpLps.build()).build();
53     }
54
55     @Override
56     public int getType() {
57         return PmsiTunnelType.RsvpTeP2mpLsp.getIntValue();
58     }
59 }