MVPN RFC6514 Extendend communities
[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.rev180329.Opaque;
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.MldpMp2mpLsp;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.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,
24                 "The tunnelIdentifier %s is not MldpMp2mpLsp type.", tunnelIdentifier);
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                 ((MldpMp2mpLsp) tunnelIdentifier).getMldpMp2mpLsp();
28         if (!OpaqueUtil.serializeOpaque(mldpMp2mpLsp, buffer)) {
29             return NO_TUNNEL_INFORMATION_PRESENT;
30         }
31         return TunnelType.M_LDP_MP_2_MP_LSP.getIntValue();
32     }
33
34     @Override
35     public TunnelIdentifier parse(final ByteBuf buffer) {
36         final Opaque opaque = OpaqueUtil.parseOpaque(buffer);
37         if (opaque == null) {
38             return null;
39         }
40         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi
41                 .tunnel.tunnel.identifier.mldp.mp2mp.lsp.MldpMp2mpLsp mldpMp2mpLsp =
42                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel
43                         .pmsi.tunnel.tunnel.identifier.mldp.mp2mp.lsp.MldpMp2mpLspBuilder(opaque).build();
44         return new MldpMp2mpLspBuilder().setMldpMp2mpLsp(mldpMp2mpLsp).build();
45     }
46 }