b0053791b88929b96ebc8e63c133bb95889dbb21
[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.rev160812.pmsi.tunnel.pmsi.tunnel.TunnelIdentifier;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.BidirPimTree;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.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, "The tunnelIdentifier %s is not BidirPimTree type.", tunnelIdentifier);
21         PAddressPMulticastGroupUtil.serializeSenderPMulticastGroup(((BidirPimTree) tunnelIdentifier).getBidirPimTree(), buffer);
22         return TunnelType.BIDIR_PIM_TREE.getIntValue();
23     }
24
25     @Override
26     public TunnelIdentifier parse(final ByteBuf buffer) {
27         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.bidir.pim.tree.
28             BidirPimTreeBuilder bidirPimTree = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.bidir.pim.tree.
29             BidirPimTreeBuilder(PAddressPMulticastGroupUtil.parseSenderPMulticastGroup(buffer));
30         return new BidirPimTreeBuilder().setBidirPimTree(bidirPimTree.build()).build();
31     }
32 }