MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / evpn / src / main / java / org / opendaylight / protocol / bgp / evpn / impl / attributes / tunnel / identifier / BidirPimTreeParser.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 com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.TunnelIdentifier;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.BidirPimTree;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.BidirPimTreeBuilder;
16
17 final class BidirPimTreeParser implements TunnelIdentifierSerializer, TunnelIdentifierParser {
18     @Override
19     public int serialize(final TunnelIdentifier tunnelIdentifier, final ByteBuf buffer) {
20         Preconditions.checkArgument(tunnelIdentifier instanceof BidirPimTree,
21                 "The tunnelIdentifier %s is not BidirPimTree type.", tunnelIdentifier);
22         PAddressPMulticastGroupUtil
23                 .serializeSenderPMulticastGroup(((BidirPimTree) tunnelIdentifier).getBidirPimTree(), buffer);
24         return TunnelType.BIDIR_PIM_TREE.getIntValue();
25     }
26
27     @Override
28     public TunnelIdentifier parse(final ByteBuf buffer) {
29         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi
30                 .tunnel.tunnel.identifier.bidir.pim.tree.BidirPimTreeBuilder bidirPimTree =
31                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel
32                         .pmsi.tunnel.tunnel.identifier.bidir.pim.tree.BidirPimTreeBuilder(PAddressPMulticastGroupUtil
33                         .parseSenderPMulticastGroup(buffer));
34         return new BidirPimTreeBuilder().setBidirPimTree(bidirPimTree.build()).build();
35     }
36 }