Add new revision for pcep types model
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / PCEPPccIdReqIPv4ObjectParser.java
1 /*
2  * Copyright (c) 2014 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.pcep.parser.object;
10
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
14 import org.opendaylight.protocol.util.Ipv4Util;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReqBuilder;
19
20 /**
21  * Parser for {@link org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReq} with IPv4 address
22  * @see <a href="https://tools.ietf.org/html/rfc5886#section-4.2">PCC-ID-REQ Object</a>
23  */
24 public final class PCEPPccIdReqIPv4ObjectParser extends AbstractPccIdReqObjectParser {
25     private static final int IPV4_TYPE = 1;
26
27     public PCEPPccIdReqIPv4ObjectParser() {
28         super(IPV4_TYPE);
29     }
30
31     @Override
32     public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
33         Preconditions.checkArgument(buffer != null && buffer.isReadable(),
34             "Array of bytes is mandatory. Can't be null or empty.");
35         final PccIdReqBuilder builder = new PccIdReqBuilder();
36         builder.setIpAddress(new IpAddressNoZone(Ipv4Util.noZoneAddressForByteBuf(buffer)));
37         return builder.build();
38     }
39 }