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