Move route target ext comm container
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / route / target / RouteTargetIpv4Handler.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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.util.ByteBufWriteUtil;
13 import org.opendaylight.protocol.util.Ipv4Util;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
16
17 /**
18  * Route Target Ipv4 Handler.
19  *
20  * @author Claudio D. Gasparini
21  */
22 public final class RouteTargetIpv4Handler {
23     private RouteTargetIpv4Handler() {
24         throw new UnsupportedOperationException();
25     }
26
27     public static void serialize(final RouteTargetIpv4 routeTarget, final ByteBuf byteAggregator) {
28         ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
29         ByteBufWriteUtil.writeUnsignedShort(routeTarget.getLocalAdministrator(), byteAggregator);
30     }
31
32     public static RouteTargetIpv4 parse(final ByteBuf buffer) {
33         return new RouteTargetIpv4Builder()
34                 .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
35                 .setLocalAdministrator(buffer.readUnsignedShort())
36                 .build();
37     }
38 }