bd4d31d9607ae1b2caafa5c3aea51ab166b657e9
[bgpcep.git] / bgp / evpn / src / main / java / org / opendaylight / protocol / bgp / evpn / 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.evpn.impl.attributes.tunnel.identifier;
10
11 import static org.opendaylight.protocol.bgp.evpn.impl.attributes.tunnel.identifier.TunnelIdentifierHandler.NO_TUNNEL_INFORMATION_PRESENT;
12
13 import com.google.common.base.Preconditions;
14 import io.netty.buffer.ByteBuf;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.Opaque;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.TunnelIdentifier;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.MldpMp2mpLsp;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.MldpMp2mpLspBuilder;
19
20 final class MldpMp2mpLspParser implements TunnelIdentifierSerializer, TunnelIdentifierParser {
21     @Override
22     public int serialize(final TunnelIdentifier tunnelIdentifier, final ByteBuf buffer) {
23         Preconditions.checkArgument(tunnelIdentifier instanceof MldpMp2mpLsp, "The tunnelIdentifier %s is not MldpMp2mpLsp type.", tunnelIdentifier);
24         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.mldp.mp2mp.lsp.
25             MldpMp2mpLsp mldpMp2mpLsp = ((MldpMp2mpLsp) tunnelIdentifier).getMldpMp2mpLsp();
26         if (!OpaqueUtil.serializeOpaque(mldpMp2mpLsp, buffer)) {
27             return NO_TUNNEL_INFORMATION_PRESENT;
28         }
29         return TunnelType.M_LDP_MP_2_MP_LSP.getIntValue();
30     }
31
32     @Override
33     public TunnelIdentifier parse(final ByteBuf buffer) {
34         final Opaque opaque = OpaqueUtil.parseOpaque(buffer);
35         if (opaque == null) {
36             return null;
37         }
38         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.mldp.mp2mp.lsp.
39             MldpMp2mpLsp mldpMp2mpLsp = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.mldp.mp2mp.lsp.
40             MldpMp2mpLspBuilder(opaque).build();
41         return new MldpMp2mpLspBuilder().setMldpMp2mpLsp(mldpMp2mpLsp).build();
42     }
43 }