Enable restart of CSS modules on blueprint container restart
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPPathKeyObjectParser.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.impl.object;
9
10 import com.google.common.base.Preconditions;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
19 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
20 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
29
30 /**
31  * Parser for {@link PathKey}
32  */
33 public class PCEPPathKeyObjectParser extends AbstractEROWithSubobjectsParser {
34
35     public static final int CLASS = 16;
36
37     public static final int TYPE = 1;
38
39     public PCEPPathKeyObjectParser(final EROSubobjectRegistry subReg) {
40         super(subReg);
41     }
42
43     @Override
44     public PathKey parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
45         Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
46         final PathKeyBuilder builder = new PathKeyBuilder();
47         builder.setIgnore(header.isIgnore());
48         builder.setProcessingRule(header.isProcessingRule());
49         final List<PathKeys> pk = new ArrayList<>();
50         final List<Subobject> subs = parseSubobjects(bytes);
51         for (final Subobject s : subs) {
52             final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase k = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase) s.getSubobjectType();
53             pk.add(new PathKeysBuilder().setLoose(s.isLoose()).setPceId(k.getPathKey().getPceId()).setPathKey(k.getPathKey().getPathKey()).build());
54         }
55         builder.setPathKeys(pk);
56         return builder.build();
57     }
58
59     @Override
60     public void serializeObject(final Object object, final ByteBuf buffer) {
61         Preconditions.checkArgument(object instanceof PathKey, "Wrong instance of PCEPObject. Passed %s. Needed PathKeyObject.", object.getClass());
62         final PathKey pkey = (PathKey) object;
63         final ByteBuf body = Unpooled.buffer();
64         final List<PathKeys> pk = pkey.getPathKeys();
65         final List<Subobject> subs = new ArrayList<>();
66         for (final PathKeys p : pk) {
67             subs.add(new SubobjectBuilder().setLoose(p.isLoose()).setSubobjectType(
68                     new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder().setPathKey(
69                             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder().setPathKey(
70                                     p.getPathKey()).setPceId(p.getPceId()).build()).build()).build());
71         }
72         serializeSubobject(subs, body);
73         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
74     }
75 }