2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.bgp.evpn.impl.attributes.tunnel.identifier;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.util.Ipv4Util;
13 import org.opendaylight.protocol.util.Ipv6Util;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.PAddressPMulticastGroup;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev160812.pmsi.tunnel.pmsi.tunnel.tunnel.identifier.bidir.pim.tree.BidirPimTreeBuilder;
18 final class PAddressPMulticastGroupUtil {
19 private PAddressPMulticastGroupUtil() {
20 throw new UnsupportedOperationException();
23 static void serializeIpAddress(final IpAddress ipAddress, final ByteBuf byteBuf) {
24 if (ipAddress.getIpv4Address() != null) {
25 byteBuf.writeBytes(Ipv4Util.bytesForAddress(ipAddress.getIpv4Address()));
27 byteBuf.writeBytes(Ipv6Util.bytesForAddress(ipAddress.getIpv6Address()));
31 static IpAddress parseIpAddress(final int ipLength, final ByteBuf buffer) {
32 if (ipLength == Ipv6Util.IPV6_LENGTH) {
33 return new IpAddress(Ipv6Util.addressForByteBuf(buffer));
34 } else if (ipLength == Ipv4Util.IP4_LENGTH) {
35 return new IpAddress(Ipv4Util.addressForByteBuf(buffer));
40 static void serializeSenderPMulticastGroup(final PAddressPMulticastGroup bidir, final ByteBuf byteBuf) {
41 serializeIpAddress(bidir.getPAddress(), byteBuf);
42 serializeIpAddress(bidir.getPMulticastGroup(), byteBuf);
45 static PAddressPMulticastGroup parseSenderPMulticastGroup(final ByteBuf buffer) {
46 final int ipLength = buffer.readableBytes() / 2;
47 final IpAddress pSenderAddress = parseIpAddress(ipLength, buffer);
48 final IpAddress pMulticastGroup = parseIpAddress(ipLength, buffer);
49 return new BidirPimTreeBuilder().setPAddress(pSenderAddress).setPMulticastGroup(pMulticastGroup).build();