2 * Copyright (c) 2015 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
8 package org.opendaylight.protocol.pcep.pcc.mock;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsIpv4ObjectParser;
14 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
15 import org.opendaylight.protocol.util.Ipv4Util;
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.endpoints.address.family.Ipv4CaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4Builder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.object.EndpointsObjBuilder;
22 public class PCCEndPointIpv4ObjectParser extends PCEPEndPointsIpv4ObjectParser {
25 public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
26 checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
27 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
28 if (bytes.readableBytes() != Ipv4Util.IP4_LENGTH * 2) {
29 throw new PCEPDeserializerException("Wrong length of array of bytes.");
31 builder.setIgnore(header.isIgnore());
32 builder.setProcessingRule(header.isProcessingRule());
33 final Ipv4Builder b = new Ipv4Builder();
34 b.setSourceIpv4Address(Ipv4Util.addressForByteBuf(bytes));
35 b.setDestinationIpv4Address(Ipv4Util.addressForByteBuf(bytes));
36 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(b.build()).build());
37 return builder.build();