Enable restart of CSS modules on blueprint container restart
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / subobject / RROPathKey128SubobjectParser.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.pcep.parser.subobject;
9
10 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
11
12 import com.google.common.base.Preconditions;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
17 import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
26
27 public class RROPathKey128SubobjectParser implements RROSubobjectParser {
28
29     public static final int TYPE = 65;
30
31     private static final int PK_F_LENGTH = 2;
32
33     protected static final int PCE128_ID_F_LENGTH = 16;
34
35     private static final int PK_F_OFFSET = 0;
36     private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
37
38     private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
39
40     @Override
41     public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
42         Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
43         if (buffer.readableBytes() != CONTENT128_LENGTH) {
44             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
45                     + CONTENT128_LENGTH + ".");
46         }
47         final int pathKey = buffer.readUnsignedShort();
48         final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
49         final SubobjectBuilder builder = new SubobjectBuilder();
50         final PathKeyBuilder pBuilder = new PathKeyBuilder();
51         pBuilder.setPceId(new PceId(pceId));
52         pBuilder.setPathKey(new PathKey(pathKey));
53         builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
54         return builder.build();
55     }
56
57     public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
58         final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
59         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
60             .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
61         final ByteBuf body = Unpooled.buffer();
62         Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
63         writeUnsignedShort(pk.getPathKey().getValue(), body);
64         Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
65         body.writeBytes(pk.getPceId().getBinary());
66         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
67     }
68 }