Moved Ipv4Util and Ipv6Util from concepts to util
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / Ipv4NlriParser.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.protocol.bgp.parser.impl.message.update;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
12 import org.opendaylight.protocol.util.ByteArray;
13 import org.opendaylight.protocol.util.Ipv4Util;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.Nlri;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv4Case;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv4CaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv4._case.DestinationIpv4Builder;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20
21 public final class Ipv4NlriParser extends IpNlriParser implements NlriSerializer {
22
23     @Override
24     protected DestinationIpv4Case parseNlri(final ByteBuf nlri) {
25         return new DestinationIpv4CaseBuilder().setDestinationIpv4(
26                 new DestinationIpv4Builder().setIpv4Prefixes(Ipv4Util.prefixListForBytes(ByteArray.readAllBytes(nlri))).build()).build();
27     }
28
29     @Override
30     public void serializeAttribute(DataObject attribute, ByteBuf byteAggregator) {
31         Nlri nlri = (Nlri) attribute;
32         for (Ipv4Prefix ipv4Prefix : nlri.getNlri()) {
33             byteAggregator.writeBytes(Ipv4Util.bytesForPrefix(ipv4Prefix));
34         }
35     }
36 }