Inherit common extensions families dependencies
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / route / target / RouteTarget4OctectASEcHandler.java
1 /*
2  * Copyright (c) 2016 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.bgp.parser.impl.message.update.extended.communities.route.target;
10
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
14 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
15 import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteTargetExtendedCommunityCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
19
20 public final class RouteTarget4OctectASEcHandler extends Abstract4OctetAsExtendedCommunity {
21     private static final int SUBTYPE = 2;
22
23     @Override
24     public ExtendedCommunity parseExtendedCommunity(final ByteBuf body)
25             throws BGPDocumentedException, BGPParsingException {
26         return new As4RouteTargetExtendedCommunityCaseBuilder()
27                 .setAs4RouteTargetExtendedCommunity(As4RouteTargetExtendedHandler.parse(body)).build();
28     }
29
30     @Override
31     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
32         Preconditions.checkArgument(extendedCommunity instanceof As4RouteTargetExtendedCommunityCase,
33                 "The extended community %s is not As4RouteTargetExtendedCommunityCase type.",
34                 extendedCommunity);
35         As4RouteTargetExtendedHandler.serialize(((As4RouteTargetExtendedCommunityCase) extendedCommunity)
36                 .getAs4RouteTargetExtendedCommunity(), body);
37     }
38
39     @Override
40     public int getSubType() {
41         return SUBTYPE;
42     }
43 }