8f5a27c8f305ae1f617621a24e91102d6bc0bbb9
[bgpcep.git] / bgp / mvpn / src / main / java / org / opendaylight / protocol / bgp / mvpn / impl / attributes / tunnel / identifier / MldpMp2mpLspParser.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.spi.pojo.attributes.tunnel.identifier.SimpleTunnelIdentifierRegistry.NO_TUNNEL_INFORMATION_PRESENT;
12
13 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.protocol.bgp.mvpn.impl.attributes.OpaqueUtil;
15 import org.opendaylight.protocol.bgp.mvpn.spi.attributes.tunnel.identifier.AbstractTunnelIdentifier;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.Opaque;
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.MldpMp2mpLsp;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.MldpMp2mpLspBuilder;
21
22 public final class MldpMp2mpLspParser extends AbstractTunnelIdentifier<MldpMp2mpLsp> {
23     @Override
24     public int serialize(final MldpMp2mpLsp tunnelIdentifier, final ByteBuf buffer) {
25         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi
26                 .tunnel.tunnel.identifier.mldp.mp2mp.lsp.MldpMp2mpLsp mldpMp2mpLsp =
27                 tunnelIdentifier.getMldpMp2mpLsp();
28         if (!OpaqueUtil.serializeOpaque(mldpMp2mpLsp, buffer)) {
29             return NO_TUNNEL_INFORMATION_PRESENT;
30         }
31         return getType();
32     }
33
34     @Override
35     public Class<? extends TunnelIdentifier> getClazz() {
36         return MldpMp2mpLsp.class;
37     }
38
39     @Override
40     public MldpMp2mpLsp parse(final ByteBuf buffer) {
41         final Opaque opaque = OpaqueUtil.parseOpaque(buffer);
42         if (opaque == null) {
43             return null;
44         }
45         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi
46                 .tunnel.tunnel.identifier.mldp.mp2mp.lsp.MldpMp2mpLsp mldpMp2mpLsp =
47                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel
48                         .pmsi.tunnel.tunnel.identifier.mldp.mp2mp.lsp.MldpMp2mpLspBuilder(opaque).build();
49         return new MldpMp2mpLspBuilder().setMldpMp2mpLsp(mldpMp2mpLsp).build();
50     }
51
52     @Override
53     public int getType() {
54         return PmsiTunnelType.MldpMp2mpLsp.getIntValue();
55     }
56 }