Move ipv4/ipv6 ByteBuf utilities to Ipv{4,6}Util
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / extended / community / Inet4SpecificExtendedCommunityCommonUtil.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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 package org.opendaylight.protocol.bgp.parser.spi.extended.community;
9
10 import static org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity.INET_LOCAL_ADMIN_LENGTH;
11
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.util.ByteArray;
14 import org.opendaylight.protocol.util.Ipv4Util;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
17
18 public final class Inet4SpecificExtendedCommunityCommonUtil {
19     private Inet4SpecificExtendedCommunityCommonUtil() {
20         // Hidden on purpose
21     }
22
23     public static Inet4SpecificExtendedCommunityCommon parseCommon(final ByteBuf buffer) {
24         return new Inet4SpecificExtendedCommunityCommonBuilder()
25                 .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
26                 .setLocalAdministrator(ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH))
27                 .build();
28     }
29
30     public static void serializeCommon(final Inet4SpecificExtendedCommunityCommon extComm,
31             final ByteBuf byteAggregator) {
32         Ipv4Util.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
33         byteAggregator.writeBytes(extComm.getLocalAdministrator());
34     }
35 }