Fixup ProtectionCommonParser.serializeBody()
[bgpcep.git] / rsvp / impl / src / main / java / org / opendaylight / protocol / rsvp / parser / impl / subobject / ero / SERODynamicProtectionSubobjectParser.java
1 /*
2  * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
9
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.EROSubobjectSerializer;
15 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.protection.subobject.ProtectionSubobject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.DynamicControlProtectionCase;
19
20 /**
21  * Parser for {@link DynamicControlProtectionCase}.
22  */
23 public class SERODynamicProtectionSubobjectParser extends ProtectionCommonParser implements EROSubobjectSerializer {
24     public static final int TYPE = 37;
25     public static final short CTYPE = 2;
26
27     @Override
28     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
29         Preconditions.checkArgument(subobject.getSubobjectType() instanceof DynamicControlProtectionCase,
30             "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
31             subobject.getSubobjectType());
32         final ProtectionSubobject protObj = ((DynamicControlProtectionCase) subobject.getSubobjectType())
33             .getDynamicControlProtection().getProtectionSubobject();
34         final ByteBuf body = Unpooled.buffer();
35         serializeBody(CTYPE, protObj, body);
36         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
37     }
38 }