f0d9f8618a8cbc03454dad608ba24b65d86645a7
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / four / octect / as / specific / 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.four.octect.as.specific;
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.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteTargetExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
21
22 public final class RouteTarget4OctectASEcHandler extends Abstract4OctetAsExtendedCommunity {
23     private static final int SUBTYPE = 2;
24
25     @Override
26     public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) throws BGPDocumentedException, BGPParsingException {
27         return new As4RouteTargetExtendedCommunityCaseBuilder().setAs4RouteTargetExtendedCommunity(new As4RouteTargetExtendedCommunityBuilder()
28             .setAs4SpecificCommon(FourOctAsCommonECUtil.parseCommon(body)).build()).build();
29     }
30
31     @Override
32     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
33         Preconditions.checkArgument(extendedCommunity instanceof As4RouteTargetExtendedCommunityCase,
34             "The extended community %s is not As4RouteTargetExtendedCommunityCase type.", extendedCommunity);
35         FourOctAsCommonECUtil.serializeCommon(((As4RouteTargetExtendedCommunityCase) extendedCommunity).getAs4RouteTargetExtendedCommunity()
36             .getAs4SpecificCommon(), body);
37     }
38
39     @Override
40     public int getSubType() {
41         return SUBTYPE;
42     }
43 }