Enable restart of CSS modules on blueprint container restart
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / PCEPOverloadObjectParser.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 io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.pcep.spi.ObjectParser;
15 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
16 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
18 import org.opendaylight.protocol.util.ByteBufWriteUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
23
24 public class PCEPOverloadObjectParser implements ObjectParser, ObjectSerializer {
25
26     public static final int CLASS = 27;
27
28     public static final int TYPE = 1;
29
30     private static final int RESERVED = 1;
31     private static final int FLAGS = RESERVED;
32     private static final int BODY_SIZE = RESERVED + FLAGS + ByteBufWriteUtil.SHORT_BYTES_LENGTH;
33
34     @Override
35     public void serializeObject(final Object object, final ByteBuf buffer) {
36         Preconditions.checkArgument(object instanceof Overload, "Wrong instance of PCEPObject. Passed %s. Needed OverloadObject.", object.getClass());
37         final Overload overload = (Overload) object;
38         final ByteBuf body = Unpooled.buffer(BODY_SIZE);
39         body.writeZero(RESERVED + FLAGS);
40         ByteBufWriteUtil.writeUnsignedShort(overload.getDuration(), body);
41         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
42     }
43
44     @Override
45     public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
46         Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
47         final OverloadBuilder builder = new OverloadBuilder();
48         buffer.readBytes(RESERVED + FLAGS);
49         builder.setDuration(buffer.readUnsignedShort());
50         return builder.build();
51     }
52
53 }