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
9 package org.opendaylight.protocol.pcep.pcc.mock;
11 import com.google.common.base.Preconditions;
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 Preconditions.checkArgument(bytes != null && bytes.isReadable(),
27 "Array of bytes is mandatory. Can't be null or empty.");
28 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
29 if (bytes.readableBytes() != Ipv4Util.IP4_LENGTH * 2) {
30 throw new PCEPDeserializerException("Wrong length of array of bytes.");
32 builder.setIgnore(header.isIgnore());
33 builder.setProcessingRule(header.isProcessingRule());
34 final Ipv4Builder b = new Ipv4Builder();
35 b.setSourceIpv4Address(Ipv4Util.noZoneAddressForByteBuf(bytes));
36 b.setDestinationIpv4Address(Ipv4Util.noZoneAddressForByteBuf(bytes));
37 builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(b.build()).build());
38 return builder.build();