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.rsvp.parser.impl.subobject.ero;
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.rsvp.parser.impl.te.ProtectionCommonParser;
14 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
15 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
16 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
17 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.protection.subobject.ProtectionSubobject;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.BasicProtectionCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.BasicProtectionCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.DynamicControlProtectionCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.basic.protection._case.BasicProtectionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.dynamic.control.protection._case.DynamicControlProtectionBuilder;
27 public class SEROBasicProtectionSubobjectParser extends ProtectionCommonParser
28 implements EROSubobjectParser, EROSubobjectSerializer {
29 public static final int TYPE = 37;
30 public static final short CTYPE = 1;
33 public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
34 Preconditions.checkArgument(buffer != null && buffer.isReadable(),
35 "Array of bytes is mandatory. Can't be null or empty.");
36 final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
37 builder.setLoose(loose);
40 final short cType = buffer.readUnsignedByte();
41 final ProtectionSubobject prot = parseCommonProtectionBody(cType, buffer);
43 builder.setSubobjectType(new BasicProtectionCaseBuilder().setBasicProtection(new BasicProtectionBuilder()
44 .setProtectionSubobject(prot).build()).build());
46 } else if (cType == SERODynamicProtectionSubobjectParser.CTYPE) {
47 builder.setSubobjectType(new DynamicControlProtectionCaseBuilder().setDynamicControlProtection(
48 new DynamicControlProtectionBuilder().setProtectionSubobject(prot).build()).build());
50 return builder.build();
54 public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
55 Preconditions.checkArgument(subobject.getSubobjectType() instanceof BasicProtectionCase,
56 "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
57 subobject.getSubobjectType());
58 final ProtectionSubobject protObj = ((BasicProtectionCase) subobject.getSubobjectType()).getBasicProtection()
59 .getProtectionSubobject();
60 final ByteBuf body = Unpooled.buffer();
61 serializeBody(CTYPE, protObj, body);
62 EROSubobjectUtil.formatSubobject(TYPE, subobject.getLoose(), body, buffer);