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